Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Andarist/callbag-remember
👜 Callbag operator that remembers last event, so that a newly added listener will immediately receive that memorised event.
https://github.com/Andarist/callbag-remember
callbag callbags
Last synced: 16 days ago
JSON representation
👜 Callbag operator that remembers last event, so that a newly added listener will immediately receive that memorised event.
- Host: GitHub
- URL: https://github.com/Andarist/callbag-remember
- Owner: Andarist
- Created: 2018-03-30T12:54:25.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-01-26T09:52:18.000Z (almost 4 years ago)
- Last Synced: 2024-10-20T06:23:05.669Z (22 days ago)
- Topics: callbag, callbags
- Language: JavaScript
- Homepage:
- Size: 14.6 KB
- Stars: 3
- Watchers: 2
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-callbags - remember
README
# 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)`](https://www.learnrxjs.io/operators/multicasting/sharereplay.html).
## Example
```js
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)
```