UNPKG

redux-compose-hors

Version:
32 lines (29 loc) 929 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = function (reducer) { for (var _len = arguments.length, hors = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { hors[_key - 1] = arguments[_key]; } var horsLength = hors.length; return function tryAllHocs(state, action) { var counter = 0; function stateActionChange(nextState, nextAction) { if (counter === horsLength) { return reducer(nextState, nextAction); } if (nextState === state && nextAction === action) { counter += 1; return; } return tryAllHocs(nextState, nextAction); } return hors.concat([function (rawReducer) { return rawReducer; }]).reduce(function (finalState, hor) { var result = hor(stateActionChange)(state, action); return result !== undefined ? result : finalState; }, state); }; };