UNPKG

simplesignal

Version:
60 lines (56 loc) 2.08 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.SimpleSignal = factory()); })(this, (function () { 'use strict'; 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; }()); return SimpleSignal; })); module.exports.default = module.exports; // Terrible injection just so it works regardless of how it's required