import type {TraceTree} from './traceTree'; type ArgumentTypes = F extends (...args: infer A) => any ? A : never; export class TraceTreeEventDispatcher { listeners: {[K in keyof TraceTree.TraceTreeEvents]: Set} = { 'trace timeline change': new Set(), }; on( event: K, cb: TraceTree.TraceTreeEvents[K] ): void { this.listeners[event].add(cb); } off( event: K, cb: TraceTree.TraceTreeEvents[K] ): void { this.listeners[event].delete(cb); } dispatch( event: K, ...args: ArgumentTypes ): void { if (!this.listeners[event]) { return; } for (const handler of this.listeners[event]) { // @ts-expect-error handler(...args); } } }