• Subscribe to an event on the bus. The payload type is inferred from evt.

    Type Parameters

    Parameters

    • evt: K

      The event name (a key of EventMap).

    • fn: ((payload) => void)

      Handler that receives the event payload.

        • (payload): void
        • Parameters

          Returns void

    Returns Unsubscribe

    A function that cancels the subscription. Call it on teardown.

    Example

    import { on } from "@urth/metatell-sdk/events";

    const off = on("chat:message", (m) => console.log(m.text));