EventBus<EM extends EventMapBase>
classMinimal, synchronous pub/sub event bus keyed by **channel** and **type**.
- Handlers are stored per
(channel, type) and invoked **synchronously** in subscription order.
- Exceptions thrown by a handler are **caught and logged**, and do **not** stop other handlers.
- Intended for in-memory, single-process usage (no cross-tab/process broadcasting).Type parameters
| Name | Type | Description |
|---|---|---|
EM | extends EventMapBase | Event map shape:
ts
type EventMapBase = Record<string, Record<string, unknown>>;
// Example:
type EM = {
ui: { toggle: boolean };
data: { loaded: { items: string[] } };
};
|
Constructor
constructor
Methods
clear
Clears **all** listeners across all channels/types. Useful for tests or during HMR teardown to avoid duplicate handlers.
emit
Emits an event to all subscribers of the exact (channel, type).
Handlers are invoked **synchronously**. Any exception thrown by a handler is
caught and logged, and other handlers still run.
off
Removes a specific handler previously added with `on`.
on
Subscribes a handler to an exact (channel, type).