A support class that implements emitting and listening for events.
This class supports inheritance or direct use:
const emitter = new EventEmitter();class MyClass extends EventEmitter {}; Copy
const emitter = new EventEmitter();class MyClass extends EventEmitter {};
When using this class from TypeScript, declare your supported event types using an interface first:
interface Events { // key: event name, value: event type "mouse-clicked": MouseEvent;}const emitter = new EventEmitter<Events>();emitter.on("mouse-clicked", (event) => { // event is a MouseEvent});emitter.emit("mouse-clicked", new MouseEvent(...)); Copy
interface Events { // key: event name, value: event type "mouse-clicked": MouseEvent;}const emitter = new EventEmitter<Events>();emitter.on("mouse-clicked", (event) => { // event is a MouseEvent});emitter.emit("mouse-clicked", new MouseEvent(...));
Use the package @conterra/reactivity-events instead.
Emits an event of the given name and calls the registered event handlers.
Note: event handlers run synchronously. After emit() has completed, all listeners will already have been invoked.
emit()
Registers the given listener function as an event handler for eventName.
eventName
The listener function should be unregistered by destroying the returned Resource when it is no longer needed.
Registers the given listener function to listen for eventName events once. The listener function will automatically be unregistered after it has been called.
The listener function should be unregistered by destroying the returned Resource.
A support class that implements emitting and listening for events.
This class supports inheritance or direct use:
When using this class from TypeScript, declare your supported event types using an interface first:
Deprecated
Use the package @conterra/reactivity-events instead.