EntityEventQueue
Defined in: entityEvents.ts:112
Entity event queue: pub/sub with bubbling support.
Example
Section titled “Example”const events = new EntityEventQueue();world.onDespawn(e => events.removeAll(e)); // one-time wiring
events.on(buttonEntity, 'click', e => console.log('clicked'));events.emit(buttonEntity, 'click');Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new EntityEventQueue():
EntityEventQueue
Returns
Section titled “Returns”EntityEventQueue
Methods
Section titled “Methods”clear()
Section titled “clear()”clear():
void
Defined in: entityEvents.ts:243
Remove all handlers and pending events.
Returns
Section titled “Returns”void
drain()
Section titled “drain()”drain(): readonly
EntityEvent<unknown>[]
Defined in: entityEvents.ts:231
Return all events queued since the last drain and clear the queue. Typically called once per frame by a UI system.
Returns
Section titled “Returns”readonly EntityEvent<unknown>[]
emit()
Section titled “emit()”emit<
TData>(entity,type,data?):EntityEvent<TData>
Defined in: entityEvents.ts:198
Emit an event for entity. Synchronously dispatches to registered
handlers and queues the event for drain() / query(). Returns the
event so callers can inspect propagationStopped / defaultPrevented
(e.g. to drive bubbling to parents).
Type Parameters
Section titled “Type Parameters”TData = unknown
Parameters
Section titled “Parameters”entity
Section titled “entity”number
string
TData
Returns
Section titled “Returns”EntityEvent<TData>
emitBubbled()
Section titled “emitBubbled()”emitBubbled(
ancestor,rootEvent):EntityEvent
Defined in: entityEvents.ts:217
Emit a bubbled event to an ancestor. Shares propagation state with the root event: calling stopPropagation on the bubbled event marks the root as stopped so callers can halt the bubbling walk.
Callers are responsible for walking the parent chain; this queue does not know about hierarchy.
Parameters
Section titled “Parameters”ancestor
Section titled “ancestor”number
rootEvent
Section titled “rootEvent”Returns
Section titled “Returns”Call Signature
Section titled “Call Signature”on(
entity,type,handler):Unsubscribe
Defined in: entityEvents.ts:125
Subscribe to an entity-specific event. Returns an unsubscribe function.
Parameters
Section titled “Parameters”entity
Section titled “entity”number
string
handler
Section titled “handler”Returns
Section titled “Returns”Call Signature
Section titled “Call Signature”on(
type,handler):Unsubscribe
Defined in: entityEvents.ts:129
Subscribe to all events of a type, from any entity.
Parameters
Section titled “Parameters”string
handler
Section titled “handler”Returns
Section titled “Returns”query()
Section titled “query()”query(
type): readonlyEntityEvent<unknown>[]
Defined in: entityEvents.ts:238
Non-destructively inspect currently-pending events of a type.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”readonly EntityEvent<unknown>[]
removeAll()
Section titled “removeAll()”removeAll(
entity):void
Defined in: entityEvents.ts:188
Remove all entity-specific handlers for entity.
Wire this to world.onDespawn for automatic cleanup.
Parameters
Section titled “Parameters”entity
Section titled “entity”number
Returns
Section titled “Returns”void