make-reducer
v0.5.1
Published
Functions to easily build redux reducers without boilerplate code.
Downloads
11
Readme
make-reducer
Functions to easily build redux reducers without boilerplate code.
Counter example
const initialState = 0;
const reducer = makeReducer(initialState);
const increment = reducer.on('INCREMENT', (counter) => counter + 1);
const decrement = reducer.on('DECREMENT', (counter) => counter - 1);
const store = createStore(reducer, initialState);
store.dispatch(increment());
store.dispatch(decrement());
You can use named functions to define actions.
const initialState = 0;
const reducer = makeReducer(initialState);
const increment = reducer.on(function INCREMENT(counter) { return counter + 1; });
const decrement = reducer.on(function DECREMENT(counter) { return counter - 1; });
const store = createStore(reducer, initialState);
store.dispatch(increment());
store.dispatch(decrement());