Skip to content

EventBus

Defined in: EventBus.ts:25

Typed publish/subscribe event bus.

E = EventMap

new EventBus<E>(): EventBus<E>

EventBus<E>

clear(event?): void

Defined in: EventBus.ts:66

Remove all handlers for an event, or all handlers if no event specified.

keyof E

void


emit<K>(event, data): void

Defined in: EventBus.ts:55

Emit an event. Handlers are called synchronously in registration order.

K extends string | number | symbol

K

E[K]

void


on<K>(event, handler): () => void

Defined in: EventBus.ts:29

Subscribe to an event. Returns an unsubscribe function.

K extends string | number | symbol

K

(data) => void

() => void


once<K>(event, handler): () => void

Defined in: EventBus.ts:46

Subscribe to an event, auto-unsubscribe after first emission.

K extends string | number | symbol

K

(data) => void

() => void