Skip to content

EventBus

Defined in: src/event-bus.ts:21

Queue-based event bus with priority-ordered handlers. Events are buffered via emit() and dispatched in batch by flush(). Handlers emitted during flush are drained within the same flush (depth-limited).

TEvent extends object

TMap extends { [E in TEvent as E["type"]]: E } = { [E in TEvent as E["type"]]: E }

new EventBus<TEvent, TMap>(): EventBus<TEvent, TMap>

EventBus<TEvent, TMap>

clear(): void

Defined in: src/event-bus.ts:31

Drop every queued event without dispatching. Useful in reset/teardown paths that want to discard stale events accumulated before a world swap or world reset. Registered handlers are not removed.

void


emit(event): void

Defined in: src/event-bus.ts:36

Queue an event for dispatch on the next flush().

TEvent

void


flush(maxDepth?): void

Defined in: src/event-bus.ts:41

Dispatch all queued events. Events emitted by handlers drain within the same flush, up to maxDepth.

number = DEFAULT_MAX_FLUSH_DEPTH

void


hasListeners<K>(type): boolean

Defined in: src/event-bus.ts:87

Whether any handler is subscribed to type. Lets a hot-path producer skip building an event nobody would receive.

K extends string

K

boolean


off<K>(type, handler): void

Defined in: src/event-bus.ts:93

Remove a previously registered handler.

K extends string

K

EventHandler<TMap, K>

void


on<K>(type, handler, priority?): () => void

Defined in: src/event-bus.ts:103

Subscribe to events of the given type. Higher priority runs first. Returns an unsubscribe function.

K extends string

K

EventHandler<TMap, K>

number = 0

() => void