Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zebulonj/callbag-subscribe
A callbag sink (listener) that connects an Observer a-la RxJS. 👜
https://github.com/zebulonj/callbag-subscribe
callbag observables reactive rx
Last synced: 3 months ago
JSON representation
A callbag sink (listener) that connects an Observer a-la RxJS. 👜
- Host: GitHub
- URL: https://github.com/zebulonj/callbag-subscribe
- Owner: zebulonj
- License: mit
- Created: 2018-02-06T19:40:41.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2021-01-28T01:24:10.000Z (almost 4 years ago)
- Last Synced: 2024-04-25T17:20:46.013Z (9 months ago)
- Topics: callbag, observables, reactive, rx
- Language: JavaScript
- Homepage:
- Size: 22.5 KB
- Stars: 18
- Watchers: 2
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-callbags - subscribe
README
# callbag-subscribe 👜
[![CircleCI](https://img.shields.io/circleci/project/zebulonj/callbag-subscribe.svg)]() [![npm](https://img.shields.io/npm/v/callbag-subscribe.svg)]() [![npm](https://img.shields.io/npm/dt/callbag-subscribe.svg)]()
A callbag sink (listener) that connects an Observer a-la RxJS.
`npm install callbag-subscribe`
## Usage:
### Simple (next only)
```js
import pipe from 'callbag-pipe';
import interval from 'callbag-interval';
import subscribe from 'callbag-subscribe';const source = interval( 10 );
pipe(
source,
subscribe( val => console.log( val ) )
);// 0
// 1
// 2
// 3
// 4
// 5
// 6
// 7
// 8
// 9
```### Complete observer
```js
import pipe from 'callbag-pipe';
import interval from 'callbag-interval';
import subscribe from 'callbag-subscribe';const source = interval( 10 );
pipe(
source,
subscribe({
next: val => console.log( val ),
complete: () => console.log( 'Done!' ),
error: err => console.error( err )
})
);// 0
// 1
// 2
// 3
// 4
// 5
// 6
// 7
// 8
// 9
// Done!
```### Disposal
Use the returned disposal function to terminate the subscription.
```js
const source = fromEvent( document.body, 'click' );const dispose = pipe(
source,
subscribe({
next: ev => console.log( 'Click:', ev )
})
);// Do some stuff...
dispose(); // Terminate the subscription.
```