sub-redux
Version:
[](https://www.npmjs.com/package/sub-redux) [](https://www.npmjs.com/package/sub-redux)
30 lines (29 loc) • 1.1 kB
JavaScript
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
// Wrap / unwrap sub actions ***************************************************
exports.wrapSubAction = function (_a) {
var instance = _a.instance, subAction = _a.subAction;
return (__assign({}, subAction, { type: "SUB_REDUX/" + instance + "/" + subAction.type }));
};
exports.unwrapSubAction = function (action) {
var match = action.type.match(/^SUB_REDUX\/([0-9a-zA-Z]+)\/(.*)$/);
if (!match) {
throw new Error('Invalid action for unwrapSubAction');
}
var instance = match[1], subType = match[2];
return {
instance: instance,
subAction: __assign({}, action, { type: subType }),
};
};
;