Class EventEmitter<T>

Emits events to registered listeners.

const emitter = new EventEmitter<string>();

const sub = emitter.event((msg) => console.log(msg));
emitter.fire('hello'); // logs: hello
sub.dispose();
emitter.fire('world'); // nothing happens

Type Parameters

  • T

Implements

Constructors

Properties

Accessors

Methods

Constructors

Properties

event: Event<T> = ...

The event that listeners can subscribe to.

Accessors

  • get listenerCount(): number

    Get the current number of listeners.

    Returns number

Methods

  • Fire the event, notifying all listeners.

    Parameters

    • data: T

      The event data to send to listeners

    Returns void

  • Subscribe to the event, but only fire once.

    Parameters

    • listener: (e: T) => void

      Callback to invoke once

    Returns IDisposable

    Disposable to cancel before the event fires