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).
Type Parameters
Section titled “Type Parameters”TEvent
Section titled “TEvent”TEvent extends object
TMap extends { [E in TEvent as E["type"]]: E } = { [E in TEvent as E["type"]]: E }
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new EventBus<
TEvent,TMap>():EventBus<TEvent,TMap>
Returns
Section titled “Returns”EventBus<TEvent, TMap>
Methods
Section titled “Methods”clear()
Section titled “clear()”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.
Returns
Section titled “Returns”void
emit()
Section titled “emit()”emit(
event):void
Defined in: src/event-bus.ts:36
Queue an event for dispatch on the next flush().
Parameters
Section titled “Parameters”TEvent
Returns
Section titled “Returns”void
flush()
Section titled “flush()”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.
Parameters
Section titled “Parameters”maxDepth?
Section titled “maxDepth?”number = DEFAULT_MAX_FLUSH_DEPTH
Returns
Section titled “Returns”void
hasListeners()
Section titled “hasListeners()”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.
Type Parameters
Section titled “Type Parameters”K extends string
Parameters
Section titled “Parameters”K
Returns
Section titled “Returns”boolean
off<
K>(type,handler):void
Defined in: src/event-bus.ts:93
Remove a previously registered handler.
Type Parameters
Section titled “Type Parameters”K extends string
Parameters
Section titled “Parameters”K
handler
Section titled “handler”EventHandler<TMap, K>
Returns
Section titled “Returns”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.
Type Parameters
Section titled “Type Parameters”K extends string
Parameters
Section titled “Parameters”K
handler
Section titled “handler”EventHandler<TMap, K>
priority?
Section titled “priority?”number = 0
Returns
Section titled “Returns”() => void