UNPKG

@aca-1/a2-composer

Version:
114 lines 3.92 kB
import { COMPOSER } from '../../../settings'; import { StatusVariable } from './status-variable.class'; var Module = (function () { function Module(srv, parent, name, i) { var _this = this; this.index = 0; this.status_variables = []; this._debug = false; this.id = name; this.service = srv; this.parent = parent; this.index = i; COMPOSER.observe('debug').subscribe(function (data) { _this._debug = data; }); } Module.prototype.bind = function (prop, cb_fn) { var val = this.get(prop); if (val.bindings > 0) { val.bindings++; val.add_cb_fn(cb_fn); val.bound(); return function () { val.unbind(); }; } else { var success = this.service.io.bind(this.parent.id, this.id, this.index, prop); if (success) { val.bindings++; val.add_cb_fn(cb_fn); return function () { val.unbind(); }; } else { return null; } } }; Module.prototype.exec = function (fn, prop, args) { var now = (new Date()).getTime(); if (prop && prop !== '') { var ids = { system_id: this.parent.id, module_name: this.id, module_index: this.index, name: prop, }; var sv_1 = this.get(prop); if (sv_1.bindings <= 0) { COMPOSER.error('Module', "Variable \"" + prop + "\"\" not bound!"); return new Promise(function (resolve, reject) { resolve({ type: 'error', message: "Error: Variable not bound!, " + fn + ", " + prop, args: args, }); }); } else { return new Promise(function (resolve, reject) { sv_1.execs.push({ prop: prop, fn: fn, value: args, resolve: resolve, reject: reject, }); }); } } else { return this.service.io.exec(this.parent.id, this.id, this.index, fn, args); } }; Module.prototype.unbind = function (prop) { var val = this.get(prop); val.bindings = 0; var id = this.service.io.unbind(this.parent.id, this.id, this.index, prop); }; Module.prototype.debug = function () { var id = this.service.io.debug(this.parent.id, this.id, this.index); }; Module.prototype.ignore = function () { var id = this.service.io.ignore(this.parent.id, this.id, this); }; Module.prototype.get = function (prop) { for (var _i = 0, _a = this.status_variables; _i < _a.length; _i++) { var variable = _a[_i]; if (variable.id === prop) { return variable; } } var s_var = new StatusVariable(this.service, this, prop, 0); this.status_variables.push(s_var); return s_var; }; Module.prototype.rebind = function () { for (var _i = 0, _a = this.status_variables; _i < _a.length; _i++) { var variable = _a[_i]; if (variable.bindings > 0) { this.bind(variable.id); } } }; Module.prototype.setDebug = function (debug) { if (typeof debug !== 'object') { return false; } this.debugger = debug; COMPOSER.log('Debugger', "Bound to module " + this.id + " " + this.index + " on system " + this.parent.id); return true; }; return Module; }()); export { Module }; //# sourceMappingURL=module.class.js.map