Ooidget Component Format 0.1Editor's Draft
Children
A widget’s children are interactive instances of other components, drawn after its layers. Unlike a
use layer, a child keeps state of its own, runs its behaviour and takes input.
The child entry
| Property | Type | Required | Description |
|---|---|---|---|
use | string | yes | The component’s name. |
props | object | no | Values placed over the child’s initial state. |
bind | object | no | { childKey: parentKey }: the child’s member childKey is the parent view’s member parentKey, read and written. |
when | Expression<boolean> | no | The child exists only while this holds, evaluated against the parent’s view (against the item’s view for a repeated child). |
x, y | Expression<number> | no | Its position at its design size, when it has no frame and the parent has no layout. Absent: 0. |
frame | Frame | no | Its box, anchored to the parent’s edges, evaluated against the parent’s view. |
each | string | no | Repeat the child once for each element of the parent view’s array member of this name. |
bindItem | object | no | For a repeated child: { childKey: itemField } binds a child member to a field of its array element. |
frameItem | Frame | no | For a repeated child: its frame, evaluated against the item’s view. |
basis, flex, min, max, align | no | Its flex item properties. |
The view of a child
The view of a child instance is computed from its parent’s view by these steps:
- Let v be a copy of the child component's initial
state. - For each member of the entry's
props, set it on v. - For each member the child itself has set (its own state, kept by the runtime per instance path), set it on v.
- For each
childKey → parentKeyofbind, if the parent's view hasparentKey, set v.childKeyto it. - If the child is repeated, set v.
indexto its index, and for eachchildKey → itemFieldofbindItemset v.childKeyto the element'sitemField. - Return v.
Writing state
When a child’s behaviour returns a state patch, the runtime routes each member:
- a member named in
bindis written to the parent, asparentKey, and so on up; - a member named in
bindItemreplaces that field of the element in the parent’s array, which is then written to the parent as a whole; - any other member is kept as the child’s own state.
Writes to the parent are applied as if the parent’s behaviour had returned them.
Instance paths
Each instance has a path: "" for the root; for a child, its parent’s path, then /, then its index in
children; for a repeated child, then . and its item index ("2/0.3"). Paths identify instances to the host, in
diagnostics and in commands.