interface WSEventBus

Delivers WSEvents to their subscribers. WSProvider creates one with createWSEventBus and emits on it as messages arrive; components subscribe through WSEventsContext, and tests emit on their own.

Properties

subscribe: <K extends keyof WSEvents>(
kind: K,
handler: (event: WSEvents[K]) => void
) => () => void

Calls handler with each event of kind, until the returned call.

emit: <K extends keyof WSEvents>(
kind: K,
event: WSEvents[K]
) => void

Calls the handlers of kind now, in the order they subscribed.

Usage

import { type WSEventBus } from "src/contexts/ws/WSContext.ts";