Skip to content

Latest commit

 

History

History
54 lines (39 loc) · 1.21 KB

README.md

File metadata and controls

54 lines (39 loc) · 1.21 KB

Arbor RXJS Binding

"Buy Me A Coffee"

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