跳转到内容

EntityEventQueue

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

Defined in: ecs/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: ecs/entityEvents.ts:271

Remove all handlers and pending events.

void


drain(): readonly EntityEvent<unknown>[]

Defined in: ecs/entityEvents.ts:259

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: ecs/entityEvents.ts:226

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: ecs/entityEvents.ts:245

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


hasListenersFor(type): boolean

Defined in: ecs/entityEvents.ts:205

Is anyone subscribed to this event type, for any entity?

For producers that must LOOK for their events rather than being handed them: a visibility watcher walks the UI tree, a proximity watcher measures distances, and neither should do that work into an empty room. Emitting is unaffected — an event with no handlers still queues for drain().

string

boolean


on(entity, type, handler): Unsubscribe

Defined in: ecs/entityEvents.ts:130

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

number

string

EntityEventHandler

Unsubscribe

on(type, handler): Unsubscribe

Defined in: ecs/entityEvents.ts:134

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

string

EntityEventHandler

Unsubscribe


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

Defined in: ecs/entityEvents.ts:266

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

string

readonly EntityEvent<unknown>[]


removeAll(entity): void

Defined in: ecs/entityEvents.ts:213

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

number

void