Overview
xTabEvent is a singleton backed by one shared BroadcastChannel (mates:xtab / MATES_XTAB_CHANNEL). Use trigger(type, data?) to publish and __subscribe((type, data) => …) (or on(…, [xTabEvent])) to listen — including from other mates packages like mates-db.
Same-origin only. Payloads use the structured clone algorithm — plain objects / primitives, not functions or DOM nodes. Discriminate messages with a namespaced type string (e.g. mates-db:sync).
Unlike plain event().__subscribe, xTabEvent.__subscribe registers cleanup on the component host when one exists.
Compared to event()
|
API
|
Delivery
|
Notes
|
|---|---|---|
event()
| In-process | Create typed channels per concern. Same JS context only. |
xTabEvent
| Cross-tab |
One shared bus — filter by type. Falls back to local-only when BroadcastChannel is unavailable (SSR).
|
xTabEvent — cross-tab sync
Shared singleton bus — open the same page in two tabs and call
xTabEvent.trigger(type, data) in one; every tab’s
subscribers receive (type, data). The demo below runs in
one preview tab.
xTabEvent.__subscribe
Direct subscribe with auto-cleanup when a component host exists. Filter by type string.