UNPKG

simplesignal

Version:
51 lines (49 loc) 1.43 kB
var SimpleSignal = /** @class */ (function () { // Constructor --- function SimpleSignal() { this.functions = []; } // Public --- SimpleSignal.prototype.add = function (func) { if (this.functions.indexOf(func) === -1) { this.functions.push(func); return true; } return false; }; SimpleSignal.prototype.remove = function (func) { var ifr = this.functions.indexOf(func); if (ifr > -1) { this.functions.splice(ifr, 1); return true; } return false; }; SimpleSignal.prototype.removeAll = function () { if (this.functions.length > 0) { this.functions.length = 0; return true; } return false; }; SimpleSignal.prototype.dispatch = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } var functionsDuplicate = this.functions.concat(); functionsDuplicate.forEach(function (func) { func.apply(void 0, args); }); }; Object.defineProperty(SimpleSignal.prototype, "numItems", { // Accessor --- get: function () { return this.functions.length; }, enumerable: false, configurable: true }); return SimpleSignal; }()); export { SimpleSignal as default };