build-reducer
Write Redux reducers with simpler syntax
build-reducer lets you write Redux reducers as individual functions, rather than one huge switch
block.
With build-reducer, writing reducers is fun using the ES2015 syntax!
const reducer = let store =
If you were to write this without build-reducer, you'd have to use a big `switch` block.
/* Traditional Redux reducer without build-reducer */ { } let store =
Install
npm install --save build-reducer
build-reducer is available via npm.
var buildReducer = // ES5
API
buildReducer
buildReducer(reducer, [defaultState])
Creates a function that calls methods from reducer
based on the given action type.
defaultState
is optional; if given, it will be used as the state if the state is currently undefined
.
More examples
You can use the implicit return arrow syntax if you have very simple functions.
const reducer =
If you prefer to use `CONSTANTS` instead of strings, you can do that with ES2015's computed property names syntax.
const RESET = 'RESET'const LOAD_PROFILE = 'LOAD_PROFILE'const RESET_PROFILE = 'RESET_PROFILE' const reducer =
build-reducer doesn't need ES2015. You can write your reducers in plain ES5.
const reducer =
Thanks
build-reducer © 2016+, Rico Sta. Cruz. Released under the MIT License.
Authored and maintained by Rico Sta. Cruz with help from contributors (list).
ricostacruz.com · GitHub @rstacruz · Twitter @rstacruz