12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- "use strict";
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.composeReducers = exports.subReducer = exports.cowValueModel = undefined;
- var _cowValueModel2 = 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 = _cowValueModel2.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 _cowValueModel = (0, _cowValueModel2.cowValueModel)(key),
- getValue = _cowValueModel.get,
- setValue = _cowValueModel.set,
- otherParts = otherKeys.map(function (each) {
- return (0, _cowValueModel2.cowValueModel)(each).get;
- });
- return function (state, action) {
- var newSubState = reducer.apply(undefined, [getValue(state), action].concat(_toConsumableArray(otherParts.map(function (getValue) {
- return getValue(state);
- }))));
- if (typeof newSubState === "undefined") {
- throw new Error("The '" + key + "' reducer must not return undefined.");
- }
- return setValue(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);
- };
- };
|