You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
454 B
26 lines
454 B
|
|
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;
|