LooseEventBus<C extends string = string, T extends string = string, P = any>
classFlexible, synchronous pub/sub bus that supports **exact** and **pattern** event subscriptions.
- **Exact handlers** subscribe to a specific
(channel, type) pair. Type keys are **normalized** by stripping a single leading dot (".foo" → "foo").
- **Pattern handlers** subscribe using wildcards over dot-separated segments:
- * matches **one** segment.
- ** matches **zero or more** segments (greedy).
- On `emit`, exact handlers fire first, then any matching pattern handlers.
- Handlers are **de-duplicated**: if the same function is both exact and pattern-registered, it is called **once**.
- Handler invocation is **synchronous**. Exceptions are caught and logged; remaining handlers still run.Type parameters
| Name | Type | Description |
|---|---|---|
C | extends string | Channel name type (defaults to string). |
T | extends string | Event type name type (defaults to string). Types are treated as **dot-separated paths** (e.g. "a.b.c"). |
P | — | Payload type for all events (defaults to any). |
Constructor
constructor
Methods
clear
Removes **all** listeners (exact and pattern). Useful for tests/HMR teardown.
emit
Emits an event to all exact subscribers first, then to **matching pattern** subscribers. Duplicate handler references are called **once** (de-duped).
off
Unsubscribes an **exact** handler. The type key is normalized internally,
so callers can pass "foo" or ".foo" interchangeably.
on
Subscribes a handler to either an **exact** type or a **pattern**.