EventEmitter
Defined in: src/core/EventEmitter.ts:28
Minimal, zero-dependency EventEmitter for both Node and browser bundles.
It implements the small, familiar surface (on / once / off / emit
…) that TaskTimer relies on, so the library ships with no runtime
dependencies. The semantics mirror the common Node/eventemitter3 API:
listeners fire in insertion order, once listeners are removed right before
they run, and emit returns whether the event had any listeners.
The optional TListener type parameter narrows the listener (and, via
Parameters<TListener>, the emit arguments) for subclasses — e.g.
TaskTimer types it to an ITaskTimerEvent listener. It defaults to
the permissive EventListener, so a bare EventEmitter is unchanged.
Extended by
Section titled “Extended by”Type Parameters
Section titled “Type Parameters”TListener
Section titled “TListener”TListener extends EventListener = EventListener
Constructor
Section titled “Constructor”new EventEmitter<
TListener>():EventEmitter<TListener>
Returns
Section titled “Returns”EventEmitter<TListener>
Methods
Section titled “Methods”eventNames()
Section titled “eventNames()”eventNames():
EventName[]
Defined in: src/core/EventEmitter.ts:38
Returns the list of event names that currently have listeners.
Returns
Section titled “Returns”listeners()
Section titled “listeners()”listeners(
event):TListener[]
Defined in: src/core/EventEmitter.ts:46
Returns the listener functions registered for the given event.
Parameters
Section titled “Parameters”Name of the event.
Returns
Section titled “Returns”TListener[]
listenerCount()
Section titled “listenerCount()”listenerCount(
event):number
Defined in: src/core/EventEmitter.ts:55
Returns the number of listeners registered for the given event.
Parameters
Section titled “Parameters”Name of the event.
Returns
Section titled “Returns”number
emit()
Section titled “emit()”emit(
event, …args):boolean
Defined in: src/core/EventEmitter.ts:67
Calls each listener registered for the given event, in insertion order, passing along any additional arguments.
Parameters
Section titled “Parameters”Name of the event to emit.
…Parameters<TListener>
Arguments forwarded to each listener.
Returns
Section titled “Returns”boolean
true if the event had listeners, otherwise false.
on(
event,fn,context?):this
Defined in: src/core/EventEmitter.ts:87
Adds a listener for the given event.
Parameters
Section titled “Parameters”Name of the event.
TListener
Listener to invoke when the event is emitted.
context?
Section titled “context?”unknown = ...
this context for the listener. Defaults to the emitter.
Returns
Section titled “Returns”this
The emitter instance for chaining.
addListener()
Section titled “addListener()”addListener(
event,fn,context?):this
Defined in: src/core/EventEmitter.ts:94
Alias of EventEmitter.on.
Parameters
Section titled “Parameters”TListener
context?
Section titled “context?”unknown = ...
Returns
Section titled “Returns”this
once()
Section titled “once()”once(
event,fn,context?):this
Defined in: src/core/EventEmitter.ts:105
Adds a one-time listener that is removed right before it is invoked.
Parameters
Section titled “Parameters”Name of the event.
TListener
Listener to invoke once when the event is emitted.
context?
Section titled “context?”unknown = ...
this context for the listener. Defaults to the emitter.
Returns
Section titled “Returns”this
The emitter instance for chaining.
off(
event,fn?,context?,once?):this
Defined in: src/core/EventEmitter.ts:118
Removes listeners for the given event. With no fn, all listeners for the
event are removed.
Parameters
Section titled “Parameters”Name of the event.
TListener
The specific listener to remove.
context?
Section titled “context?”unknown
Only remove listeners bound to this context.
boolean
Only remove one-time listeners.
Returns
Section titled “Returns”this
The emitter instance for chaining.
removeListener()
Section titled “removeListener()”removeListener(
event,fn?,context?,once?):this
Defined in: src/core/EventEmitter.ts:142
Alias of EventEmitter.off.
Parameters
Section titled “Parameters”TListener
context?
Section titled “context?”unknown
boolean
Returns
Section titled “Returns”this
removeAllListeners()
Section titled “removeAllListeners()”removeAllListeners(
event?):this
Defined in: src/core/EventEmitter.ts:151
Removes all listeners, or all listeners for the given event.
Parameters
Section titled “Parameters”event?
Section titled “event?”Name of the event. Omit to remove listeners for all events.
Returns
Section titled “Returns”this
The emitter instance for chaining.