redux-immutable-combine-reducers
v0.1.1
Published
A Redux combineReducers that returns an Immutable Map
Downloads
213
Maintainers
Readme
redux-immutable-combine-reducers
A Redux combineReducers that returns an Immutable Map
Install
npm install --save redux-immutable-combine-reducers
Purpose
To have a root that is also an Immutable Map. Redux's combineReducers works with Immutable, but the root is still a plain object. This utility will return an Immutable Map instead.
Usage
import combineReducers from 'redux-immutable-combine-reducers';
import {Map} from 'immutable';
function counter(state = 0, action = {}) {
switch (action.type) {
case 'INCREMENT':
return state + 1;
case 'DECREMENT':
return state - 1;
default:
return state;
}
}
function filter(state = '', action = {}) {
switch (action.type) {
case 'SET_FILTER':
return action.filter;
default:
return state;
}
}
const objReducer = combineReducer({counter, filter});
const objState = objReducer();
console.log(objState.get('counter'));
// => 0
const mapReducer = combineReducer(Map({counter, filter}));
const mapState = mapReducer();
console.log(mapState.get('counter'));
// => 0
API
combineReducers(reducers)
Returns a reducer function that always returns an Immutable.Map.
reducers
Type: object
| Immutable.Map
An object
or Immutable.Map
with all keys or entries being functions.
LICENSE
MIT © Dustin Specker