red-redux-class
Version:
Use objects and composition for creating complex reducers which can be easily maintained.
47 lines • 2.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var ReduxClass_constants_1 = require("./ReduxClass.constants");
var ReduxClassException_class_1 = require("./ReduxClassException.class");
function bindPrototype(prototype, key, _target, needsNew) {
if (needsNew === void 0) { needsNew = false; }
if (typeof prototype[key] === 'function') {
if (needsNew) {
return function () {
this._shouldBeNew();
return prototype[key].apply(this[ReduxClass_constants_1.ARRAY_KEY], arguments);
};
}
return function () {
return prototype[key].apply(this[ReduxClass_constants_1.ARRAY_KEY], arguments);
};
}
throw new ReduxClassException_class_1.ReduxClassException("No such method '" + key + "()' in '" + prototype.constructor.name + "' prototype", 'Provide proper method keys of prototype');
}
exports.bindPrototype = bindPrototype;
function bindMethods(target, source, keys, needsNew, method, exclude) {
var e_1, _a;
if (needsNew === void 0) { needsNew = false; }
if (method === void 0) { method = bindPrototype; }
if (exclude === void 0) { exclude = []; }
try {
for (var keys_1 = tslib_1.__values(keys), keys_1_1 = keys_1.next(); !keys_1_1.done; keys_1_1 = keys_1.next()) {
var key = keys_1_1.value;
if (source.prototype[key]) {
if (exclude.indexOf(key) === -1) {
var desc = Object.getOwnPropertyDescriptor(source.prototype, key);
Object.defineProperty(target.prototype, key, tslib_1.__assign(tslib_1.__assign({}, desc), { value: method(source.prototype, key, target, needsNew) }));
}
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (keys_1_1 && !keys_1_1.done && (_a = keys_1.return)) _a.call(keys_1);
}
finally { if (e_1) throw e_1.error; }
}
}
exports.bindMethods = bindMethods;
//# sourceMappingURL=reflection.utils.js.map