Reading another section
How one section's slot follows or derives from another's — declared on the slot that depends, and settled before any renderer runs.
What it is
A slot that depends on another section says so on its own source:. There are two
shapes. A mirror holds another slot's value outright — its source: is a slot ref
off the other section's value. A derivation computes from it —
compute({ reads }, fn) with the slot ref among its reads:
import { compute, fact, fill, Section, section, Slot, text } from "@homepages/concrete";
const headline = text.medium({
label: "Headline",
cap: 60,
source: fill.write({ reads: [fact.property.description], brief: "What makes the property worth seeing. Write one sentence. Confident and specific." }),
});
const Hero = section(
{ key: "hero", label: "Hero", slots: { headline } },
({ slot }) => (
<Section>
<Slot.Text slot={slot.headline} as="h1" />
</Section>
),
);
const Footer = section(
{
key: "footer",
label: "Footer",
slots: {
// A mirror: the footer holds the hero's headline.
echo: text.medium({ label: "Echo", cap: 60, source: Hero.slots.headline }),
// A derivation: the hero's headline, or the city when it has none.
tagline: text.short({
label: "Tagline",
cap: 60,
source: compute(
{ reads: [Hero.slots.headline, fact.property.address.city] },
(heroHeadline, city) => heroHeadline ?? city ?? "",
),
}),
},
},
({ slot }) => (
<Section as="footer">
<Slot.Text slot={slot.echo} as="p" />
<Slot.Text slot={slot.tagline} as="p" />
</Section>
),
);The dependency lives in the section that has it. The template composes the two and declares nothing about how they relate.
Why it works this way
A renderer that could reach across sections would stop being a function of its bindings — and the platform would lose the property everything else rests on: that it can render one section, in isolation, from a content document. So the reading happens before rendering, at derive time, and the renderer sees an ordinary binding.
Putting the read on the dependent slot is what makes it maintainable. The slot's own declaration says where its value comes from — a fact, a fill, a computation or another slot — and one look at it answers "why does this say that". It is also what the platform needs to keep the page consistent: every read is indexed, so an edit to an upstream slot knows exactly which slots to settle again.
And a callback sees exactly what it declared. There is no view of the whole site or
the whole property to reach into, so a read cannot be forgotten: a value the body
uses is a value its reads listed.
How it works
A ref names a section, not an instance. Hero.slots.headline comes off the
section value, so a slot is written without knowing how the template composes.
When the composition is materialized, each ref resolves to the instance that
section was placed as — the first placement in page order when it was placed more
than once.
One positional value per ref. A compute's callback takes one argument per ref,
in reads order, each at the ref's own value type. A slot value is always
| undefined: the upstream section may be unplaced, on a disabled page, or empty,
and the callback decides what that means. A direct mirror of a missing upstream takes
its slot kind's empty value, as an unfilled slot does.
A sibling slot is its own const. Inside one section, Section.slots.* does not
exist yet, so a slot reads a sibling through the const it was declared as —
reads: [headline], or source: headline for a mirror. A field of one of the
section's top-level objects is read the same way, by the const it was declared as, so
slots that read each other can still share a card. A field of a list's item is not:
it is one value per item, and it reads its own element or a row beside it.
Declaration order keeps those reads acyclic: a const cannot be read before it exists.
A list follows a list the same way. A list's source: may be another section's
list, by its slot ref, or a sibling list, by its const. It then holds that list's
elements in that list's order — the comparables one section picked, shown again in
another — and its own item says what each is made of here.
An object's field has a ref of its own. An object's ref hands out one per field,
at that field's value type — Hero.slots.agent.fields.contact — so another section
mirrors or reads a field without the object around it. That is how a row the user
re-picks is shared across the page: the row is a field of an object, whose editor
card shows its bar, every other section that names the same contact mirrors it
there, and a re-pick in the card moves every mirror.
A display entry is a ref too. A section value hands out a ref per declared
display entry — Hero.display.visibility — so a section's variant or visibility may
follow another section's. It may read its own section's slots too, through their
consts, even a slot its variant gates: the gate decides which fields the editor
shows, never which slots are filled.
Reads form a DAG. Across sections the reads follow the import graph, and
concrete check holds them to it: a loop is
relations/section-cycle, a read of a section no
page places is relations/unplaced-read, and a
mirror holding a different kind of value than its upstream — a row of another table,
a list of another element — is
relations/mirror-type.
Settled once every fill has run. A fill writes what it writes; then every slot
that reads another settles over the whole page, upstream first, so a mirror of a
mirror settles in one pass. A fill may therefore not read a slot that settles after
it — relations/fill-reads-computed.
A mirror edits its upstream; a derivation stands. A mirror holds no value of its own, so a user's edit to it is an edit to the upstream slot, and every mirror of that slot follows (where an edit goes). A derivation is linked until a user edits it. An edit upstream settles every linked derivation again; a user edit to the derivation itself marks it overridden, and from then on it keeps the user's value until they clear the override.
What it is not
It is not a way for one section's code to write into another. A value flows toward the slot that reads it; the one edit that travels the other way is a user's, typed into a mirror.
It is not visibility by itself. Whether a section renders is its own display
entry's business; that entry may read another section, but the decision is still its
own.
It is not a subscription at render time. By the time a renderer runs, the value has already settled, and the renderer sees it as an ordinary binding like any other.
Where next
Follow another section's value
has the recipe end to end, alongside its neighbours —
a display variant and
a visibility rule.
Sources states compute({ reads }) and the slot-ref source
member by member, and Compute a value
covers derivations over facts. The report that names a loop or an unplaced read
comes from concrete check.
