UNPKG

@mousepox/util

Version:

Miscellaneous utilities

23 lines (22 loc) 487 B
export class Signal { constructor() { this.receivers = []; } receive(receiver) { this.receivers.push(receiver); } ignore(receiver) { const index = this.receivers.indexOf(receiver); if (index !== -1) { this.receivers.splice(index, 1); } } purge() { this.receivers.length = 0; } emit(...args) { for (const receiver of this.receivers) { receiver(...args); } } }