@shoutem/redux-composers
Version:
Reducers you can use for composing reducer hierarchy like with combineReducers from redux
26 lines (22 loc) • 959 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = chainReducers;
var _reduce2 = _interopRequireDefault(require("lodash/reduce"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
/**
* Chains multiple reducers, each reducer will get the state returned by
* the previous reducer. The final state will be the state returned by
* the last reducer in the chain.
* @param reducers: Order of reducers in array defines the order of execution of reducers in chain
* @returns {Function}: A reducer that invokes every reducer inside the reducers array in chain
* order, and constructs a state object or array depending on nature of reducers.
*/
function chainReducers(reducers) {
return function (state, action) {
return (0, _reduce2["default"])(reducers, function (chainState, reducer) {
return reducer(chainState, action);
}, state);
};
}