Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/staltz/callbag-pseudo-rxjs
👜 Proof of concept that implements a subset of RxJS using callbags
https://github.com/staltz/callbag-pseudo-rxjs
Last synced: 5 days ago
JSON representation
👜 Proof of concept that implements a subset of RxJS using callbags
- Host: GitHub
- URL: https://github.com/staltz/callbag-pseudo-rxjs
- Owner: staltz
- Created: 2018-01-31T10:54:44.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-01-31T13:44:51.000Z (almost 7 years ago)
- Last Synced: 2024-11-01T07:24:36.638Z (12 days ago)
- Language: JavaScript
- Homepage:
- Size: 6.84 KB
- Stars: 21
- Watchers: 5
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
- awesome-callbags - pseudo-rxjs
README
# callbag-pseudo-rxjs
This is a proof of concept to demonstrate how an RxJS-style API can be built using callbags under the hood. It shows that the [Callbag spec](https://github.com/callbag/callbag) does not dictate the API you find in [callbag-basics](https://github.com/staltz/callbag-basics). Check the source code for this repo and you'll find that we use callbags as implementation, but the external API mimics RxJS.
`npm install callbag-pseudo-rxjs`
## example
Pick the first 5 odd numbers from a clock that ticks every second, then subscribe to it:
```js
const Observable = require('callbag-pseudo-rxjs');Observable.interval(1000)
.map(x => x + 1)
.filter(x => x % 2)
.take(5)
.subscribe({
next: x => console.log(x),
error: e => {},
complete: () => {}
});// 1
// 3
// 5
// 7
// 9
```Log XY coordinates of click events on `` elements:
```js
const Observable = require('callbag-pseudo-rxjs');Observable.fromEvent(document, 'click')
.filter(ev => ev.target.tagName === 'BUTTON')
.map(ev => ({x: ev.clientX, y: ev.clientY}))
.subscribe({
next: x => console.log(x),
error: e => {},
complete: () => {}
});// {x: 110, y: 581}
// {x: 295, y: 1128}
// ...
```