Type AliasEventBusChannel<T>

EventBusChannel<T>: {
    emit<Key>(key: Key, ...payload: Parameters<T[Key]>): void;
    off<Key>(key: Key, handler: T[Key]): void;
    on<Key>(key: Key, handler: T[Key]): (() => void);
}

Defines the interface for the Event Bus Channel. Provides methods to subscribe, unsubscribe, and emit events.

Type Parameters

  • T extends EventMap

    The EventMap defining all possible events and their handlers.

Type declaration

  • emit:function
    • Emits an event, invoking all subscribed handlers with the provided payload.

      Type Parameters

      • Key extends string | number | symbol

        The key of the event to emit.

      Parameters

      • key: Key

        The event key.

      • Rest...payload: Parameters<T[Key]>

        The data to pass to each event handler.

      Returns void

  • off:function
    • Unsubscribes a handler from a specific event.

      Type Parameters

      • Key extends string | number | symbol

        The key of the event to unsubscribe from.

      Parameters

      • key: Key

        The event key.

      • handler: T[Key]

        The event handler function to remove.

      Returns void

  • on:function
    • Subscribes a handler to a specific event.

      Type Parameters

      • Key extends string | number | symbol

        The key of the event to subscribe to.

      Parameters

      • key: Key

        The event key.

      • handler: T[Key]

        The event handler function.

      Returns (() => void)

      A function to unsubscribe the handler from the event.

        • (): void
        • Returns void