123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- "use strict";
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.subEffex = exports.subMiddleware = exports.composeReducers = exports.subReducer = undefined;
- var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
- 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); } }
- 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);
- };
- };
- var subMiddleware = exports.subMiddleware = function subMiddleware(keyOrSelectorFn, middleware) {
- var cow = typeof keyOrSelectorFn === "function" ? keyOrSelectorFn : (0, _cowValueModel.cowValueModel)(keyOrSelectorFn);
- return function (store) {
- for (var _len3 = arguments.length, rest = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
- rest[_key3 - 1] = arguments[_key3];
- }
- var _getState = store.getState;
- return middleware.apply(undefined, [_extends({}, store, { getState: function getState() {
- return cow(_getState());
- } })].concat(rest));
- };
- };
- var subEffex = exports.subEffex = function subEffex(keyOrSelectorFn, effects) {
- return effects.map(function (each) {
- return _extends({}, each, { effect: subMiddleware(keyOrSelectorFn, each.effect) });
- });
- };
|