concrete/contract/object
An object groups value slots, rows, lists of value slots and lists of objects one level deep, holds no value of its own, is labelled by its label field, and names no field like its binding's own keys.
An object groups value slots, rows, lists of value slots and lists of objects one level deep, holds no value of its own, is labelled by its label field, and names no field like its binding's own keys.
Graded by the contracts stage of concrete check, in the contract venue. A violation reports this id and the file it failed at — see every rule and concrete check.
Reason
An object is a pure container: it groups fields into one card, at the top level and
as a list's item alike, and holds no value of its own. Its value is its fields'
values, so a source or a bound on the object itself has nothing to act on.
A field is a value slot, a row, a list of value slots, or a list of objects one
level deep — never another object. Every value is addressed by a flat tuple
(instance, slot, item, field), and a nested object has no place in it. A list of
objects as a field is one field: its items carry their own ids, minted when the
section bakes, so it lists only what yields content — a row's list-valued member,
a compute(), or authored items — and never a fill, a fact table or
another list slot. Each of its item fields reads the item's element or a row
declared beside it, and none is filled or computed; its item holds no list of
objects again.
A field is read straight off its object's binding in render — slot.address.street,
item.price — beside the binding's own keys: id, slot, index, def, value,
present, and on an item of a list of objects inside an object, its enclosing
field's address under the key enclosing. A field
named like one of them would read as the binding's own, so no field takes those names.
The card's title is the object's label, and it takes its text the way a text slot's
source: does: a fact, a row member, a list's element, another section's slot, a
compute(), or a fill.write that names the text kind it writes. It is stored as a
locked text field keyed label — the card's header, never a field anyone edits. A
title the user edits is one of the object's fields, and the label names it by its
const; that label is stored as a pointer to the field, { field }, so the header
follows the field as it changes. A plain string is a constant: compute(() => "…").
Check-caught, and type-caught where the builder can see it: object takes no
source, no field keyed label or named like a binding's own key, no
string label and no text slot built in place as its label. The stored form is what publishing grades, whatever
produced it: a label field that is not locked, a pointer to a field that is not
text, or both at once.
Fix
Move nested fields up into the object, or declare the inner list at the top level —
the home of a list of objects that is filled, reads a fact table or another list,
or nests a second level.
Rename a field named like a binding's own key for what it holds — a value that
holds a figure is named for the figure. The renamed field is a new field to every
site already made: its value under the old name, and any edit to it, is not carried
across, and the new field fills afresh. Write the label as a source; to let the user edit the title, declare it as a field and
name that field as the label.
Before and after
// A string label, and an editable title built in place as the label: both are refused.
// @noErrors
import { fact, object, row, text } from "@homepages/concrete";
const agent = row({ label: "Agent", from: fact.property.contacts });
object({
label: "Listing agent",
fields: { agent, phone: text.short({ label: "Phone", source: agent.phone }) },
});
object({
label: text.short({ label: "Name", source: agent.name }),
fields: { agent },
});import { compute, fact, object, row, text } from "@homepages/concrete";
const agent = row({ label: "Agent", from: fact.property.contacts });
const name = text.short({ label: "Name", source: agent.name });
object({
label: compute(() => "Listing agent"),
fields: { agent, phone: text.short({ label: "Phone", source: agent.phone }) },
});
object({ label: name, fields: { agent, name } });