create-reduxreducer
create-reduxreducer
creates a reducer from an object. so you can easyly split your reduce functions as individual function for each actionType instead of use switch case for filter them.
Table of contents
Installation
You can install it via npm. If you'll use it in a Isomorphic/Universal App i recommend you installing it as production dependency.
$ npm install create-reduxreducer --save
Usage
It only takes two arguments: an object with the action types as a key and the reduce function that will handle the actionType and an initial state.
In this example we define an actionHandlers object and it's reduce functions:
myReducer.js
;; const actionHandlers = ActionTypesINPUT_NUMBER: inputNumber ActionTypesINPUT_DECIMAL: inputDecimal ...; { ...} { ...} const myReducer = ; ;
Then you can use this reducer as a regular redux reducer and pass it to combineReducers when you configure your store.
If you want to use arrow functions remember to define your actionHandlers object after your arrow functions:
;; const imputNumber = state;const imputDecimal = state; const actionHandlers = ActionTypesINPUT_NUMBER: inputNumber ActionTypesINPUT_DECIMAL: inputDecimal ...; const myReducer = ;
You can pass as initial state whatever you want, regular objets or even ImmutableJs objects:
; const DataModel = ; actionHandlers ;
Projects using create-reduxreducer
- [react-base](https://github.com/atSistemas/react-base/ (atSistemas React/Redux Isomorphic Platform)
License
MIT