fluxtuate
Version:
a javascript ES7 library for handling complex data transactions
67 lines (50 loc) • 2.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.updateFunction = updateFunction;
exports.nameProperty = nameProperty;
exports.bindModel = bindModel;
exports.autoDispatch = autoDispatch;
var _internals = require("./_internals");
function updateFunction(target, name) {
target[_internals.fluxtuateUpdateFunction] = name;
}
function nameProperty(target, name) {
target[_internals.fluxtuateNameProperty] = name;
}
function processBindProperty(bindFunction, target, key, descriptor) {
if (key === undefined || typeof descriptor.value === "function") throw new Error("You can only bind properties of a mediator!");
if (!target[_internals.boundModels]) target[_internals.boundModels] = [];
target[_internals.boundModels].push({ key: key, bindFunction: bindFunction });
return descriptor;
}
function bindModel(bindFunction) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
if (args.length === 0) {
return processBindProperty.bind(this, bindFunction);
} else if (args.length === 2) {
return processBindProperty.apply(this, [function (payload) {
return payload.data;
}, bindFunction].concat(args));
}
}
function processDispatchProperty(dispatchKey, target, key, descriptor) {
if (key === undefined) throw new Error("You can only bind properties of a mediator!");
if (!target[_internals.autoDispatches]) target[_internals.autoDispatches] = [];
target[_internals.autoDispatches].push({ key: key, dispatchKey: dispatchKey });
descriptor.configurable = true;
return descriptor;
}
function autoDispatch(dispatchKey) {
for (var _len2 = arguments.length, args = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
args[_key2 - 1] = arguments[_key2];
}
if (args.length === 0) {
return processDispatchProperty.bind(this, dispatchKey);
} else if (args.length === 2) {
return processDispatchProperty.apply(this, [args[0], dispatchKey].concat(args));
}
}