export type EventMap = { 'dialog:unsafeRoles': { action: 'confirm' | 'dismiss'; }; // add more events as required }; export type EventName = keyof EventMap; export type EventCallback = (data: EventMap[T]) => void; class EventBus { private listeners: { [K in EventName]?: Array> } = {}; public on(event: T, callback: EventCallback): () => void { if (!this.listeners[event]) { this.listeners[event] = []; } this.listeners[event]?.push(callback as any); return () => { this.off(event, callback); }; } public off(event: T, callback: EventCallback): void { if (!this.listeners[event]) return; const callbackIndex = this.listeners[event]?.indexOf(callback as any); if (callbackIndex !== undefined && callbackIndex > -1) { this.listeners[event]?.splice(callbackIndex, 1); } } public emit(event: T, data: EventMap[T]): void { if (!this.listeners[event]) return; this.listeners[event]?.forEach(callback => { callback(data); }); } } export const eventBus = new EventBus();