跳转到内容

EntityEventQueue

此内容尚不支持你的语言。

Defined in: entityEvents.ts:112

Entity event queue: pub/sub with bubbling support.

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');

new EntityEventQueue(): EntityEventQueue

EntityEventQueue

clear(): void

Defined in: entityEvents.ts:243

Remove all handlers and pending events.

void


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.

readonly EntityEvent<unknown>[]


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).

TData = unknown

number

string

TData

EntityEvent<TData>


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.

number

EntityEvent

EntityEvent


on(entity, type, handler): Unsubscribe

Defined in: entityEvents.ts:125

Subscribe to an entity-specific event. Returns an unsubscribe function.

number

string

EntityEventHandler

Unsubscribe

on(type, handler): Unsubscribe

Defined in: entityEvents.ts:129

Subscribe to all events of a type, from any entity.

string

EntityEventHandler

Unsubscribe


query(type): readonly EntityEvent<unknown>[]

Defined in: entityEvents.ts:238

Non-destructively inspect currently-pending events of a type.

string

readonly EntityEvent<unknown>[]


removeAll(entity): void

Defined in: entityEvents.ts:188

Remove all entity-specific handlers for entity. Wire this to world.onDespawn for automatic cleanup.

number

void