Skip to content

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.

TListener extends EventListener = EventListener

new EventEmitter<TListener>(): EventEmitter<TListener>

EventEmitter<TListener>

eventNames(): EventName[]

Defined in: src/core/EventEmitter.ts:38

Returns the list of event names that currently have listeners.

EventName[]


listeners(event): TListener[]

Defined in: src/core/EventEmitter.ts:46

Returns the listener functions registered for the given event.

EventName

Name of the event.

TListener[]


listenerCount(event): number

Defined in: src/core/EventEmitter.ts:55

Returns the number of listeners registered for the given event.

EventName

Name of the event.

number


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.

EventName

Name of the event to emit.

Parameters<TListener>

Arguments forwarded to each listener.

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.

EventName

Name of the event.

TListener

Listener to invoke when the event is emitted.

unknown = ...

this context for the listener. Defaults to the emitter.

this

The emitter instance for chaining.


addListener(event, fn, context?): this

Defined in: src/core/EventEmitter.ts:94

Alias of EventEmitter.on.

EventName

TListener

unknown = ...

this


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.

EventName

Name of the event.

TListener

Listener to invoke once when the event is emitted.

unknown = ...

this context for the listener. Defaults to the emitter.

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.

EventName

Name of the event.

TListener

The specific listener to remove.

unknown

Only remove listeners bound to this context.

boolean

Only remove one-time listeners.

this

The emitter instance for chaining.


removeListener(event, fn?, context?, once?): this

Defined in: src/core/EventEmitter.ts:142

Alias of EventEmitter.off.

EventName

TListener

unknown

boolean

this


removeAllListeners(event?): this

Defined in: src/core/EventEmitter.ts:151

Removes all listeners, or all listeners for the given event.

EventName

Name of the event. Omit to remove listeners for all events.

this

The emitter instance for chaining.