Emitter <Events>
Implements
- TypedEventEmitter<Events>
Index
Constructors
Methods
Constructors
constructor
Methods
emit
Emits an event with a given name and passes any number of arguments to the listeners. Returns a boolean indicating whether the event had listeners attached.
Type parameters
- Event: string | number | symbol
Parameters
event: Event
The name of the event to be emitted.
rest...args: Parameters<Events[Event]>
Any number of arguments to be passed to the listeners.
Returns boolean
A boolean indicating whether the event had listeners attached.
eventNames
Returns an array of all the event names that have listeners.
Returns (string | symbol | keyof Events)[]
An array of event names.
listenerCount
Returns the number of listeners for the given event.
Type parameters
- Event: string | number | symbol
Parameters
event: Event
The event name.
Returns number
The number of listeners for the given event.
listeners
Returns an array of listeners for the specified event.
Type parameters
- Event: string | number | symbol
Parameters
event: Event
The event name to retrieve listeners for.
Returns Events[Event][]
An array of listeners for the specified event.
off
Removes a listener from the specified event.
Type parameters
- Event: string | number | symbol
Parameters
event: Event
the event to remove the listener from.
listener: Events[Event]
the listener to remove from the event.
Returns this
The class instance for chaining.
on
Adds a listener for the specified event.
Type parameters
- Event: string | number | symbol
Parameters
event: Event
The event name.
listener: Events[Event]
The listener function.
Returns this
Returns this instance for chaining.
once
Returns a proxy function that when called, invokes the original listener function and removes the listener from the event emitter.
Type parameters
- Event: string | number | symbol
Parameters
event: Event
The event to listen to.
listener: Events[Event]
The listener function to be called once.
Returns Events[Event]
The original listener function.
removeAllListeners
Removes all listeners for the specified event or all events if none specified.
Type parameters
- Event: string | number | symbol
Parameters
optionalevent: Event
The event to remove listeners for.
Returns this
Returns the instance for chaining.
Cross-platform, lightweight type-safe event emitter.