libp2p
    Preparing search index...

    Interface TypedEventTarget<EventMap>

    An event target with a typed map of supported events

    interface TypedEventTarget<EventMap extends Record<string, any>> {
        addEventListener<K extends string | number | symbol>(
            type: K,
            listener: EventHandler<EventMap[K]> | null,
            options?: boolean | AddEventListenerOptions,
        ): void;
        dispatchEvent(event: Event): boolean;
        dispatchEvent(event: Event): boolean;
        listenerCount(type: string): number;
        removeEventListener<K extends string | number | symbol>(
            type: K,
            listener?: EventHandler<EventMap[K]> | null,
            options?: boolean | EventListenerOptions,
        ): void;
        removeEventListener(
            type: string,
            listener?: EventHandler<Event>,
            options?: boolean | EventListenerOptions,
        ): void;
        safeDispatchEvent<Detail>(
            type: keyof EventMap,
            detail?: CustomEventInit<Detail>,
        ): boolean;
    }

    Type Parameters

    • EventMap extends Record<string, any>

    Hierarchy (View Summary)

    Implemented by

    Index
    • Add a listener for an event

      Type Parameters

      • K extends string | number | symbol

      Parameters

      Returns void

    • The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. The normal event processing rules (including the capturing and optional bubbling phase) also apply to events dispatched manually with dispatchEvent().

      MDN Reference

      Parameters

      Returns boolean

    • The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. The normal event processing rules (including the capturing and optional bubbling phase) also apply to events dispatched manually with dispatchEvent().

      MDN Reference

      Parameters

      Returns boolean

    • Returns the number of listeners for the event type

      Parameters

      • type: string

      Returns number

    • Remove a listener previously registered for an event

      Type Parameters

      • K extends string | number | symbol

      Parameters

      Returns void

    • The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target. The event listener to be removed is identified using a combination of the event type, the event listener function itself, and various optional options that may affect the matching process; see Matching event listeners for removal.

      MDN Reference

      Parameters

      • type: string
      • Optionallistener: EventHandler<Event>
      • Optionaloptions: boolean | EventListenerOptions

      Returns void

    • Type-safe version of EventTarget.dispatchEvent - only events from the event map are supported.

      Attempting to dispatch an unsupported event results in a TypeScript compilation error.

      Type Parameters

      • Detail

      Parameters

      Returns boolean