Class EventDispatcher<EventKeyType, EventMessageType>

Handles notifying listeners of events.

EventKeyType is used to distinguish events (e.g. a ClickEvent vs a TouchEvent) while EventMessageType is the type of the data sent with an event (can be void).

const dispatcher = new EventDispatcher<'event1'|'event2'|'event3', void>();
dispatcher.on('event1', () => {
console.log('Event 1 triggered.');
});
dispatcher.dispatch('event1');

Type Parameters

  • EventKeyType extends string | symbol | number
  • EventMessageType

Constructors

Methods

Constructors

Methods

  • Removes an event listener. This is equivalent to calling .remove() on the object returned by .on.

    Parameters

    Returns void

OpenSource licenses