Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/monojack/xsrx
Pipeable operators for xstream, with rxjs compatibility layer
https://github.com/monojack/xsrx
compat observable operators pipe rxjs xstream
Last synced: about 2 months ago
JSON representation
Pipeable operators for xstream, with rxjs compatibility layer
- Host: GitHub
- URL: https://github.com/monojack/xsrx
- Owner: monojack
- Created: 2020-05-05T21:20:51.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T05:42:05.000Z (about 2 years ago)
- Last Synced: 2024-10-31T17:46:41.816Z (3 months ago)
- Topics: compat, observable, operators, pipe, rxjs, xstream
- Language: JavaScript
- Size: 482 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## xsrx
Pipeable operators for `xstream`, with `rxjs` compatibility layer.
**Reason**: Being an avid `rxjs` user I want to be able to use `xstream's` hot streams without having to "switch" to a different syntax. As a bonus: if I ever want to refactor to `rxjs` I'd only have to replace the imports.
_NOTE:_ Does **NOT** convert from `xstream` to `rxjs`, so even though you wouldn't have to go through all your codebase to change operator names and from dot[.]chaining to piping, you might still have to deal with the fact that you're switching from hot to cold observables.
**TL;DR**
```js
xs.periodic(1000)
.mapTo(1)
.fold((acc, c) => acc + c, 1)
.map(id =>
xs.from(
fetch(`https://swapi.dev/api/people/${id}`).then(res => res.json()),
),
)
.flatten()
.map(data => data.name)// to
interval(1000).pipe(
mapTo(1),
scan((acc, c) => acc + c, 1),
switchMap(id =>
from(fetch(`https://swapi.dev/api/people/${id}`).then(res => res.json())),
),
pluck('name'),
)// or using the pipeline operator
// https://github.com/tc39/proposal-pipeline-operator
interval(1000)
|> mapTo(1)
|> scan((acc, c) => acc + c, 1)
|> switchMap(id =>
from(fetch(`https://swapi.dev/api/people/${id}`).then(res => res.json())),
)
|> pluck('name')// and it's still an `xstream` Stream
```_Imports are the same as in `rxjs`_
```js
import { interval } from 'xs.rx'
import { mapTo, scan, switchMap, pluck } from 'xs.rx/operators'
```