Elements talking to each other
Events up, attributes down — the platform's own protocol, and hydrargyri already
speaks both halves. There is no bus, no store, no $dispatch: on
listens to any event name, custom events included, and they bubble.
<demo-cart on="item-picked:refresh">
<p>Picked: <output bind="count">0</output></p>
<demo-item sku="7"><button on="click:pick">add sku 7</button></demo-item>
<demo-item sku="9"><button on="click:pick">add sku 9</button></demo-item>
</demo-cart>
hg("demo-item", {
attributes: ["sku"],
handlers: {
pick(e, el) {
el.dispatchEvent(
new CustomEvent("item-picked", {
bubbles: true,
detail: { sku: el.sku },
}),
);
},
},
});
hg("demo-cart", {
properties: ["count"],
connected(el) {
el.count = 0;
},
handlers: {
refresh(e, el) {
el.count += 1;
},
},
});The cart's on sits on the cart, and the event is raised two levels down. It
arrives because it bubbles, and because a nested hydrargyri element does not swallow
what passes through it.
The footgun is the platform's
Forget bubbles: true and the event reaches nobody, silently — CustomEvent
defaults it to false, and nothing in hydrargyri or the browser will tell you. It
is the one line in this page worth remembering.
Downwards
Plainer still. A parent writes a child's observed attribute, and the child repaints and reacts on its own:
el.querySelector("demo-item").sku = 9;
That is not a hydrargyri API — it is a property on a custom element, set the way any
property is set. The child's attribute changes, its binds repaint, and its
attributeChanged runs. Nothing had to be registered for that to work.
Sideways
Siblings never hear each other: an event travels up, not across. So the two halves above compose into the third — the common ancestor catches the bubbling event and writes the other sibling.
<demo-mixer on="dose-picked:pour">
<demo-dose amount="1"><button on="click:pick">add 1</button></demo-dose>
<demo-dose amount="5"><button on="click:pick">add 5</button></demo-dose>
<demo-vessel amount="0">
<p>In the vessel: <output bind="amount">0</output></p>
</demo-vessel>
</demo-mixer>
hg("demo-dose", {
attributes: ["amount"],
handlers: {
pick(e, el) {
el.dispatchEvent(
new CustomEvent("dose-picked", {
bubbles: true,
detail: { amount: el.amount },
}),
);
},
},
});
hg("demo-vessel", { attributes: ["amount"] });
hg("demo-mixer", {
handlers: {
pour(e, el) {
el.querySelector("demo-vessel").amount += e.detail.amount;
},
},
});The relay writes a property, never the sibling's nodes. bind="amount" inside
demo-vessel belongs to demo-vessel — binds go to the nearest hydrargyri ancestor,
and a hydrargyri element is its own — so the mixer could not paint that <output>
even if it tried. It sets the value; the vessel repaints itself.
Which is also why the relay has to be a hydrargyri element: it needs an on of its
own to catch the event. A plain <div> between two siblings relays nothing.
No common ancestor at all
A button in the header, the element it drives at the bottom of the page. The
platform's own answer is
commandfor/command:
the button names any element by id, the browser fires a command event on
that element, and a handler under the command's exact name answers it.
<button commandfor="cart" command="--add-item">Add</button>
<!-- …anywhere else in the document… -->
<x-cart id="cart">…</x-cart>
hg("x-cart", {
attributes: ["count"],
handlers: {
"--add-item": (e, el) => {
el.count += 1;
},
},
});
Command keys live in handlers beside the named ones: the exact command
strings, dashes and all — no name transformation to reason backwards through,
and since custom commands must start with --, a command key cannot collide
with a handler name. An unknown command warns; an element with no -- keys
declared stays silent, since on="command:name" can handle commands its own
way instead.
Baseline newly available (December 2025). Older browsers leave the button inert — nothing breaks and nothing happens, which is the failure mode to weigh before choosing it. A page that must work everywhere keeps the bubbling event above, or loads invokers-polyfill itself — hydrargyri does not bundle it, since an element only listens and a page using no commands should not pay for one.
The proposal and the
polyfill both trace to @keithamus with
@lukewarlow co-championing the spec. Command
keys in handlers exist because that work made commands worth answering.
There is no live preview here for that reason: it would demonstrate one thing in a current browser and an empty box in an older one, without saying which you were looking at.
Scope, and where it stops
| Between | Through |
|---|---|
| child → ancestor | a bubbling event, caught by the ancestor's on |
| parent → child | writing the child's observed attribute |
| sibling → sibling | both of the above, via their common ancestor |
| any element → any element | commandfor/command, where the browser is new enough |
| anything wider | the page's job, not hydrargyri's |
State shared across a whole page — a session, a router, a cart that outlives the markup around it — belongs to the page. Hydrargyri holds state on elements, and an element is a subtree. A library that solved the wider case would need a store, and a store is the thing this one refuses to grow.
Nesting
Binds and handlers belong to the nearest hydrargyri ancestor, whatever its tag —
so a hydrargyri element inside another hydrargyri element keeps its own nodes, and neither
paints into the other's. That is what makes the cart above work: bind="count"
is the cart's, on="click:pick" is the item's, and the two do not negotiate.