UNPKG

redux-vertical

Version:
23 lines 1.23 kB
"use strict"; 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 constants_1 = __importDefault(require("./constants")); const toString_1 = __importDefault(require("./utils/toString")); function handleAction(type, reducer = (x) => x, defaultState) { invariant_1.default(type, 'type should be a string or an async type object'); const types = toString_1.default(type).split(constants_1.default.separator); invariant_1.default(typeof reducer === 'function', 'reducer should be a function but got %s', reducer); invariant_1.default(!(defaultState === undefined), `defaultState for reducer handling %s should be defined but got %s`, types.join(', '), defaultState); return function actionHandler(state = defaultState, action) { const actionType = toString_1.default(action.type); if (!actionType || !types.includes(actionType)) { return state; } return reducer(state, action); }; } exports.default = handleAction; //# sourceMappingURL=handle-action.js.map