Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/staltz/callbag-subject
👜 A callbag listener sink which is also a listenable source
https://github.com/staltz/callbag-subject
Last synced: 5 days ago
JSON representation
👜 A callbag listener sink which is also a listenable source
- Host: GitHub
- URL: https://github.com/staltz/callbag-subject
- Owner: staltz
- Created: 2018-02-01T16:17:40.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-04-20T07:01:50.000Z (over 1 year ago)
- Last Synced: 2024-12-22T04:46:52.742Z (22 days ago)
- Language: JavaScript
- Homepage:
- Size: 24.4 KB
- Stars: 27
- Watchers: 5
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
- awesome-callbags - subject
README
# callbag-subject
A callbag listener sink which is also a listenable source, and maintains an internal list of listeners. Use this like you would use RxJS Subject.
`npm install callbag-subject`
## example
First call `makeSubject` to create a `subject` which is then a normal callbag, so:
- Call it with args `(1, data)` to send data into the subject
- Call it with args `(2, err)` to send an error into the subject
- Call it with args `(2)` to make the subject complete```js
const observe = require('callbag-observe');
const makeSubject = require('callbag-subject');const subject = makeSubject();
setInterval(() => { subject(1, 'a'); }, 1000);
// First observer is added immediately
observe(x => console.log(x + 1))(subject);// First observer is added after 2.5 seconds
setTimeout(() => {
observe(x => console.log(x + 2))(subject);
}, 2500);// a1
// a1
// a1
// a2
// a1
// a2
// ...
```