npm.io
1.1.0 • Published 9 years ago

reducer-generator-reducer

Licence
MIT
Version
1.1.0
Deps
0
Vulns
0
Weekly
0

reducer-generator-reducer

A reducer-generator which builds a reducer that reduces a reducer. In most cases this is not useful. It is, however, useful for libraries that are building reducers from various object types as it allows us to inject arguments into the reduction chain.

Installation

yarn add reducer-generator-reducer

or

npm install --save reducer-generator-reducer

Simple Example

import createReducerReducer from 'reducer-generator-reducer'

const system = createReducerReducer(
  { /* initial state */ },
  (state, action) => {
    switch(action.type) {
      case 'SYSTEM_ONLINE': {
        return {
          ...state,
          isOnline: true
        }
      }
      case 'SYSTEM_OFFLINE': {
        return {
          ...state,
          isOnline: false
        }
      }
    }
    return state
  }, 
  /* You may pass extra args that will be passed to the reducer(s) */ 
)

Keywords