redux-vertical
Version:
Build redux vertically
24 lines • 1.24 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const invariant_1 = __importDefault(require("invariant"));
const handle_action_1 = __importDefault(require("./handle-action"));
const isPlainObject_1 = __importDefault(require("./utils/isPlainObject"));
function createReducers(handlers, defaultState) {
return Object.keys(handlers).map((type) => {
invariant_1.default(typeof handlers[type] === 'function', 'handleActions expects a function for each key but found %s for %s', handlers[type], type);
return handle_action_1.default(type, handlers[type], defaultState);
});
}
function handleActions(handlers, defaultState) {
invariant_1.default(isPlainObject_1.default(handlers), 'handleActions expects an object for handlers but found %s', handlers);
const reducers = createReducers(handlers, defaultState);
function reducer(state = defaultState, action) {
return reducers.reduce((state, reducer) => reducer(state, action), state);
}
return reducer;
}
exports.default = handleActions;
//# sourceMappingURL=handle-actions.js.map