Skip to content

👜 Callbag operator that remembers last event, so that a newly added listener will immediately receive that memorised event.

Notifications You must be signed in to change notification settings

Andarist/callbag-remember

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

callbag-remember

Callbag operator which shares input stream between subscribers and emits last emitted value upon subscription. It behaves pretty much as Rx's .shareReplay(1).

Example

import fromEvent from 'callbag-from-event'
import forEach from 'callbag-for-each'
import map from 'callbag-map'
import merge from 'callbag-merge'
import pipe from 'callbag-pipe'
import remember from 'callbag-remember'

const focus$ = remember(
  merge(
    map(() => false)(fromEvent(window, 'blur')),
    map(() => true)(fromEvent(window, 'focus')),
  ),
)

pipe(
  focus$,
  forEach(tabFocused => {
    // ...
  }),
)

// ...

setTimeout(() => {
  pipe(
    focus$,
    forEach(tabFocused => {
      // ... will get last emitted value immediately
    }),
  )
}, 1000)

About

👜 Callbag operator that remembers last event, so that a newly added listener will immediately receive that memorised event.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •