Skip to content

Initializing reducers action and associated higher order reducer for redux.

License

Notifications You must be signed in to change notification settings

oreshinya/initializable-reducer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Initializable reducer

npm version Build Status

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

About

Initializing reducers action and associated higher order reducer for redux.

Resources

License

Stars

Watchers

Forks

Packages

No packages published