redux-kefir-1
v1.0.1
Published
Kefir bindings for Redux
Downloads
1
Maintainers
Readme
redux-kefir-1
Kefir bindings for Redux
npm install --save-dev redux-kefir-1
createProjection(store: ReduxStore): KefirProperty
Creates an observable of state over time from a Redux store.
import { createProjection } from 'redux-kefir-1'
Usage
Given store
, create a projection:
const stateProjection = createProjection(store)
To do anything useful with the newly minted stateProjection
, we must use the Kefir API.
observableMiddleware: ReduxMiddleware
Enables dispatching Kefir observables and Flux Standard Actions that have observable payloads.
import { observableMiddleware } from 'redux-kefir-1'
Usage
createStore = applyMiddleware(observableMiddleware)(createStore)
Or when using ngRedux
:
$ngReduxProvider.createStoreWith(reducers, [observableMiddleware])
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
:
const obs = () => Kefir.sequentially(50, [1, 2])
Dispatch new observable stream, mapping its values through the action creator:
const obsWithCount = store.dispatch(obs().map(count))
Or dispatch an FSA that has observable payload, essentially, inverting control:
const obsWithCount = store.dispatch(count(obs()))
Both examples have the same outcome.
Note that dispatch will not subscribe to the observable obs
(unlike in the original version of refux-kefir), instead allowing to subscribe at any later point, thus giving much more flexibility:
obsWithCount
.onAny(event => {
console.log('event:', event);
});
// event: Object {type: "value", value: 1}
// event: Object {type: "value", value: 2}
// event: Object {type: "end", value: undefined}