Skip to content

Class: Emitter<Events> ​

Experimental

Minimal typed event emitter used by the render loop and render root.

Listener lists are copy-on-write arrays so emit (called every frame) iterates by index without allocating, and listeners may unsubscribe themselves during dispatch. A listener that throws does not stop the others: its error is reported (reportError) and dispatch carries on.

Type Parameters ​

Type Parameter
Events extends object

Constructors ​

Constructor ​

ts
new Emitter<Events>(): Emitter<Events>;

Experimental

Returns ​

Emitter<Events>

Methods ​

clear() ​

ts
clear(): void;

Experimental

Returns ​

void


emit() ​

ts
emit<K>(type, payload): void;

Experimental

Type Parameters ​

Type Parameter
K extends string | number | symbol

Parameters ​

ParameterType
typeK
payloadEvents[K]

Returns ​

void


has() ​

ts
has(type): boolean;

Experimental

Whether anything listens to type (lets callers skip building payloads).

Parameters ​

ParameterType
typekeyof Events

Returns ​

boolean


on() ​

ts
on<K>(type, listener): () => void;

Experimental

Subscribe to type. Returns an idempotent unsubscribe function.

Type Parameters ​

Type Parameter
K extends string | number | symbol

Parameters ​

ParameterType
typeK
listener(payload) => void

Returns ​

() => void

Released under the MIT License.