export type ActionWithType = { type: string }; export type ActionHandler = ( action: TAction, ) => void | Promise; export class ActionBus { private handlers = new Map>(); register(type: TAction["type"], handler: ActionHandler): void { this.handlers.set(type, handler); } async dispatch(action: TAction): Promise { const handler = this.handlers.get(action.type); if (!handler) { throw new Error(`No handler registered for action: ${action.type}`); } await handler(action); } }