initializable-reducer
v1.0.0
Published
Redux higher order reducer for initializing state by a action.
Downloads
49
Readme
Initializable reducer
Initializing reducers action and associated higher order reducer for redux.
Installation
$ npm i --save initializable-reducer
Usage
import { createStore } from 'redux';
import { initializeReducers, enableInitializing } from 'initializable-reducer';
const count = (num) => {
return { type: 'COUNT', num };
};
// Wrap a reducer if you want to make initializable.
const countReducer = enableInitializing((prevState=2, action) => {
switch(action.type) {
case 'COUNT':
return action.num;
default:
return prevState;
}
});
const store = createStore(countReducer);
store.dispatch(count(100));
store.getState(); // => 100
// Initialize reducers
store.dispatch(initializeReducers());
store.getState(); // => 2
LICENSE
MIT