Class EventEmitter<T>

Class that can handle event dispatching. Users can register event handlers for certain events and when the emit() function is called, this class will take care of invoking all of the event handlers that were registered for events of that type.

Type Parameters

  • T extends Record<string, any[]>

Hierarchy (view full)

Constructors

Properties

Methods

Constructors

Properties

events: Partial<Record<keyof T, Listener<T[keyof T]>[]>> = {}

Methods

  • Fires the event, calling all registered listeners with the provided arguments.

    Type Parameters

    • K extends string | number | symbol

    Parameters

    • event: K

      The event name.

    • Rest ...args: T[K]

      The arguments for the listeners.

    Returns void

  • Removes a listener for the event.

    Type Parameters

    • K extends string | number | symbol

    Parameters

    • event: K

      The event name.

    • listener: Listener<T[K]>

      The listener callback.

    Returns void

  • Registers a new listener for the event.

    Type Parameters

    • K extends string | number | symbol

    Parameters

    • event: K

      The event name.

    • listener: Listener<T[K]>

      The listener callback.

    Returns (() => void)

    A function that removes the listener when called.

      • (): void
      • Returns void