Higher-order Redux reducer which helps apply your existent reducers on any format of state
npm install redux-map-state --save
import mapState from 'redux-map-state';
// or
var mapState = require('redux-map-state');
import mapState from 'redux-map-state/es6';
Use this if you are using rollup.js or webpack 2, or any ES2015 modules-compatible bundler which can eliminate unused library code with tree-shaking.
It is recommended to import the library from redux-map-state/es6
instead of
redux-map-state/src
because the source code depends on experimental presets from
babel (stage 1-3) and may be incompatible with your bundler or settings.
Use the Universal Module Definition (UMD)
- mapState.js
- mapState.min.js (minified)
mapState(
options: {
before: ?(stateBefore: any) => newStateBefore,
after: ?(stateAfter: any) => newStateAfter,
actionTypes: ?Array<string>
}
): (reducer) => reducer
Creates a higher-order reducer which maps state before and after passing to a reducer, but does it only for passed action types.
Useful when you want reuse your reducer on state, which has another format.
Lets say we have reducer which handles list of objects, but we want to use it on subtree, which is only one object.
import listReducer from 'listReducer';
const objectReducer = mapState({
before: (obj) => [obj],
after: (list) => list[0]
})(listReducer);