export type EventHandler = (arg: T) => void; export class EventDelegate { private handlers: EventHandler[] = []; public add(handler: EventHandler) { this.handlers.push(handler); return handler; } public remove(handler: EventHandler) { this.handlers = this.handlers.filter((h) => h !== handler); } public trigger(input: T) { for (const h of this.handlers) { h(input); } } }