extend-reducer

0.1.2 • Public • Published

extend-reducer

Extend reducer with other reducers.

npm install --save extend-reducer

Example

 
const init = { field: 1 }
 
const root = (prev = init, curr) => ({...prev, field: prev.field + curr})
const some = (prev = init, curr) => ({...prev, field: prev.field + curr})
 
const reducer = extendReducer(root, { some })
 
// state structure
const state = {
  field: 1,
  some: {
    field: 1,
  },
}
 
const next = reducer(state, 3)
 
// result
// { field: 4,
//   some: {
//     field: 4,
//   },
// }

Why?

Sometimes we need to add some Redux reducer as a key to another core reducer. Also it fill uncovered with combineReducer and reduceReducers cases.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.1.2
    2
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.1.2
    2
  • 0.1.1
    1
  • 0.1.0
    0

Package Sidebar

Install

npm i extend-reducer

Weekly Downloads

3

Version

0.1.2

License

MIT

Last publish

Collaborators

  • pofigizm