1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- "use strict";
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.composeReducers = exports.subReducer = exports.cowValueModel = undefined;
- var _cowValueModel = require("./cow-value-model");
- function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
- exports.cowValueModel = _cowValueModel.cowValueModel;
- var subReducer = exports.subReducer = function subReducer(key, reducer) {
- for (var _len = arguments.length, otherKeys = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
- otherKeys[_key - 2] = arguments[_key];
- }
- var value = (0, _cowValueModel.cowValueModel)(key),
- otherParts = otherKeys.map(function (each) {
- return (0, _cowValueModel.cowValueModel)(each);
- });
- return function (state, action) {
- var newSubState = reducer.apply(undefined, [value(state), action].concat(_toConsumableArray(otherParts.map(function (value) {
- return value(state);
- }))));
- if (typeof newSubState === "undefined") {
- throw new Error("The '" + key + "' reducer must not return undefined.");
- }
- return value(state, newSubState);
- };
- };
- var composeReducers = exports.composeReducers = function composeReducers() {
- for (var _len2 = arguments.length, reducers = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
- reducers[_key2] = arguments[_key2];
- }
- return function (state, action) {
- return reducers.reduce(function (x, r) {
- return r(x, action);
- }, state);
- };
- };
|