@arborjs/rxjs
v0.0.1-alpha.94
Published
rxjs binding for @arborjs/store
Downloads
29
Maintainers
Readme
Arbor RXJS Binding
RXJS binding for @arborjs/store.
[!WARNING] This is currently an experimental project, use it at your own risk in production.
Installation
Via npm
npm install @arborjs/rxjs
Or via yarn
yarn add @arborjs/rxjs
Make sure you have @arborjs/store
installed.
Usage
import { Arbor } from "@arborjs/store"
import { from } from "@arborjs/rxjs"
import { filter } from "rxjs/operators"
const store = new Arbor({
count: 0
})
// 1. Create an Observable version of the store
const observable = from(store)
// 2. Use RXJS APIs to process a stream of mutation events triggered by the store
observable
.pipe(filter((event) => event.state.count % 2 === 0))
.forEach((event) => {
console.log("Even count:", event.state.count)
})
.catch(console.error)
store.state.count++
store.state.count++
=> Even count: 2
store.state.count++
store.state.count++
=> Even count: 4