refinery-js

0.6.1 • Public • Published

refinery

wercker status dependency status code coverage npm version

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
// }

Readme

Keywords

none

Package Sidebar

Install

npm i refinery-js

Weekly Downloads

17

Version

0.6.1

License

none

Last publish

Collaborators

  • platane