/** * Callback invoked with the payload of an emitted event. */ type Handler = (evt: T) => void; /** * Typed publish/subscribe bus, where `Events` maps each event name to its payload type. */ interface EventBusOptions = Record> { /** * Registers a handler for an event. Registering the same handler twice invokes it twice. * * @returns The bus, for chaining. */ on(type: K, handler: Handler): EventBusOptions; /** * Removes one registration of a handler, matched by reference. * * @returns The bus, for chaining. */ off(type: K, handler: Handler): EventBusOptions; /** * Invokes every handler registered for the event, synchronously and in registration order. Handlers iterate over * the live array, so removing a handler during dispatch can skip the next one. */ emit(type: K, ...evt: undefined extends Events[K] ? [evt?: Events[K]] : [evt: Events[K]]): void; /** * Removes all handlers for all events. */ clear(): void; } /** * Creates an isolated event bus. Each call returns a bus with its own handler registry. * * @example * ```ts * const bus = EventBus<{ 'config:change': { theme: string } }>(); * * bus.on('config:change', ({ theme }) => applyTheme(theme)); * bus.emit('config:change', { theme: 'aura' }); * ``` */ declare function EventBus = Record>(): EventBusOptions; export { EventBus, type EventBusOptions, type Handler };