loading... Pacem JS

<pacem-broadcastchannel-proxy> lets the tabs of your site talk to each other: the cart badge that updates everywhere, the "logged out" that logs out every tab. Same channel-name, and a message sent here shows up as result there.

<pacem-broadcastchannel-proxy channel-name="cart" message="{{ #cart.model.count }}"
                              on-receive="#cart.model = { count: $event.detail }"></pacem-broadcastchannel-proxy>

Usage

Tune in. Every proxy with the same channel-name, in any tab or frame of the same origin, shares the channel. Change the name and the proxy moves to the new channel.

Send. With autosend (the default), every change of message goes out; turn it off and call send() (or send(something)) when you mean it. Messages are structured-cloned: objects and arrays travel fine, functions and DOM nodes don't.

Receive. An arriving message lands in result and fires receive ($event.detail is the message).

A channel never hears its own messages: the other tabs do (and so do other proxies of the same name on this page). Echoing a received value back with autosend is harmless: an unchanged message isn't sent again.

Examples

Log out from every tab

Two proxies on one page play two tabs: logging out in one reaches the other.

An announcement, sent on demand

autosend="false": typing doesn't broadcast, the button does. Open a second tab to receive it there too.