function Dispatcher() { this.hooks = []; } Dispatcher.prototype.hook = function(cb) { this.hooks.push(cb); return this.hooks.length-1; }; Dispatcher.prototype.unhook = function(index) { this.hooks[index] = null; }; Dispatcher.prototype.signal = function(value) { for(const cb of this.hooks) { if(cb) cb.apply(this, [value]); } }; Dispatcher.prototype.clear = function() { this.hooks = []; }; export default Dispatcher;