refinery-js
v0.6.1
Published
reactive Redux reducer
Downloads
12
Readme
refinery
Reactive Redux reducer
Let you build your application state as small reducer with dependency relations.
usage
// fragment the state, declare a reducer for each
// this fragment is updated when an action is dispatched
const A = ( action, a = 0 ) => {
if ( 'A:increment' == action.type )
return a + 1
else
return a
}
A.source = true
// this one too
const B = ( action, b = 0 ) => {
if ( 'B:increment' == action.type )
return b + 1
else
return b
}
B.source = true
// this fragment depends on others, it is updated when the dependencies change
const sum => ( a, b ) =>
a + b
sum.dependencies = [ A, B ]
// usage with redux
import createReducer from 'refinery-js'
import { createStore } from 'redux'
// create the reducer from the fragments
const { reduce, initState } = createReducer( { A, B, sum } )
// create redux store
const store = createStore( reduce, initState )
store.dispatch({type:'A:increment'})
store.getState()
// {
// A : 1
// B : 0
// sum : 1
// }