redux-kefir
Kefir bindings for Redux
npm install --save redux-kefir
ReduxStore): KefirProperty
createProjection(store:Creates an observable of state over time from a Redux store.
import { createProjection } from 'redux-kefir'
Usage
Given store
, create a projection:
let stateProjection = createProjection(store)
To do anything useful with the newly minted stateProjection
, we must use the Kefir API.
ReduxMiddleware
observableMiddleware:Enables dispatching Kefir observables and Flux Standard Actions that have observable payloads.
import { observableMiddleware } from 'redux-kefir'
Usage
createStore = applyMiddleware(observableMiddleware)(createStore)
Given a store
and an action creator count(payload: number): FSA
, dispatch a stream of count
actions. For clarity and DRY, we'll define a stream creator obs
:
let obs = () => Kefir.sequentially(50, [1,2,3])
Dispatch new observable stream, mapping its values through the action creator:
store.dispatch(obs().map(count))
Or dispatch an FSA that has observable payload, essentially, inverting control:
store.dispatch(count(obs()))
Both examples have the same outcome:
at t + 0.05s dispatched {type: "count", payload: 1}
,
at t + 0.10s dispatched {type: "count", payload: 2}
,
at t + 0.15s dispatched {type: "count", payload: 3}
,
then ended.