Amazon Vinyl
    Preparing search index...

    Interface EventHost<EventMap>

    An object that may dispatch events and have handlers for those events. Similar to the DOM's EventTarget, this is a basic event system based on event naming.

    Some of the advantages of EventHost over EventTarget:

    • Not all supported platforms support EventTarget construction or extension.
    • EventTarget is designed for the DOM, with bubble and capture phases not necessary in Vinyl.
    • Event types are strict.
    • Events can be plain objects, no need to extend CustomEvent.
    • Easier unsubscription and disposal; reduces the risk of memory leaks.

    EventHost supports concurrent modification, that is, handlers may be added or removed during the execution of another handler.

    interface EventHost<EventMap> {
        logPrefix: string;
        dispatch<K extends string | number | symbol>(
            type: K,
            event: EventMap[K],
        ): void;
        hasAnyListeners(): boolean;
        hasListeners(type: keyof EventMap): boolean;
        on<K extends string | number | symbol>(
            type: K,
            handler: EventHandler<EventMap[K]>,
            options?: SignalOptions,
        ): Unsubscribe;
    }

    Type Parameters

    • EventMap

    Hierarchy (View Summary)

    Implemented by

    Index
    logPrefix: string

    A string prefix for all log statements made by this target.

    • Dispatches an event.

      Type Parameters

      • K extends string | number | symbol

      Parameters

      • type: K

        The key of the event within EventMap

      • event: EventMap[K]

        If the passed event is read-only, then it may be re-used/cached. Otherwise, it should be a new event object every dispatch. If no target property is set on the event, the target will be set to this host.

      Returns void