export default class EventBus>> { private readonly events: { [K in keyof E]?: { [eventId: string]: (data: E[K]) => void } } = {} public dispatch(eType: T, data: E[T]) { for (const eventId in this.events[eType]) { ;(this.events[eType] as any)[eventId](data) } } public on(eType: T, id: string, callback: (data: E[T]) => void) { if (!this.events[eType]) this.events[eType] = {} const events = this.events[eType] as any if (events[id]) { throw new Error(`${id} is already registered for ${eType.toString()}`) } events[id] = callback } public off(eType: T, id: string) { delete (this.events[eType] || ({} as any))[id] } }