Overview
event<T>(name?) creates a typed in-process pub/sub channel. Call it at module level so senders and receivers share one instance. Fire with .trigger(data?); listen with on(fn, [myEvent]) (preferred in components) or .__subscribe(fn).
on(..., [event]) registers cleanup on the host so the handler is removed on unmount. Plain event().__subscribe does not auto-clean — keep the returned unsubscribe (or use onCleanup).
Optional name shows up in devtools traces. The generic T is TypeScript-only.
Not exported from mates: channel and cleanupEvent live under lib/Mutables/events/ but are not re-exported from lib/index.ts. Treat them as internal — use public event / xTabEvent instead.
event vs other communication
|
API
|
Scope
|
Notes
|
|---|---|---|
event()
| In-process | Same JS context only — no browser API overhead. Public export. |
xTabEvent
| Cross-tab |
Singleton bus — trigger(type, data) over one shared BroadcastChannel.
|
atom
| Shared state | Prefer atoms when you need a current value, not a fire-and-forget signal. |
channel / cleanupEvent
| Internal |
Exist in source but not exported from mates.
|
event — decoupled communication
Module-level channels, senders trigger, receivers __subscribe. Keep unsubs for long-lived mounts (or prefer on()).
on() with an event dependency
Pass the event in the deps array. on() auto-unsubscribes when the component unmounts.