x4js - v2.2.49
    Preparing search index...

    Class EventSource<E>

    A base class for objects that can emit and listen to custom events. It provides a typed eventing mechanism, allowing for the registration and removal of listeners, and the firing of events with associated payloads.

    Type Parameters

    • E extends EventMap = EventMap

      An EventMap-shaped type that defines the events supported by this source.

    Hierarchy (View Summary)

    Index
    • Creates an instance of EventSource.

      Type Parameters

      • E extends EventMap = EventMap

        An EventMap-shaped type that defines the events supported by this source.

      Parameters

      • source: unknown = null

        The object that will be reported as the source of events fired by this instance. If null or undefined, the EventSource instance itself will be the source.

      Returns EventSource<E>

    • Registers an event listener for a specific event name.

      Type Parameters

      • K extends string | number | symbol

      Parameters

      • name: K

        The name of the event to listen for (must be a key in E).

      • callback: (ev: E[K]) => void

        The function to be called when the event is fired.

      • capturing: boolean = false

        If true, the listener will be added to the beginning of the listener list (capturing phase).

      Returns () => void

    • Dispatches an event with a given name and payload to all registered listeners.

      Type Parameters

      • K extends string | number | symbol

      Parameters

      • name: K

        The name of the event to fire (must be a key in E).

      • evx: E[K]

        The event payload (event object) to pass to the listeners.

      Returns void

    • Removes a previously registered event listener.

      Type Parameters

      • K extends string | number | symbol

      Parameters

      • name: K

        The name of the event from which to remove the listener.

      • callback: (ev: E[K]) => any

        The specific callback function to remove. It must be the same function instance that was originally registered.

      Returns void