Skip to content

Ariadne: repeat: {children: key}, an instance per child of a state key, named by it - #1585

Merged
transfix merged 3 commits into
masterfrom
ariadne/repeat-children
Nov 30, 2026
Merged

transfix merged 3 commits into
masterfrom
ariadne/repeat-children

Conversation

@transfix

Copy link
Copy Markdown
Owner

repeat: {children: KEY} draws a template once per child of a state key, in name order, worked out each frame. {key} is the child's name, filled in wherever {i} is today ({i} is its place this frame). An instance is its child, not a position, so adding or removing a site leaves the other sites' instances as they were.

This is what nicotina needs to drop its numbered slots.<i> (cy-pca/nicotina#46, docs/COMPONENTS.md 3.6, CD-10): one module per site, at includes.<site>, named by the site:

windows:
  - load: nicotina.ari
    as: "{key}"                      # includes.tx_wtf for sites.tx_wtf
    repeat: {children: sites}
    name: sites.{key}.host
    link:
      session: {to: "sessions.{key}", mode: rw}

Don't merge without Joe's OK.

What changes

  • Loader (loader.cpp):
    • repeat: takes a map {children: KEY} on any widget, a load: included (Widget::repeat_children; repeat holds the key).
    • An expression, a missing key or an unknown map key warns.
    • as: keeps {key} and {i} as written for each instance to fill in. With no repeat: to fill them in, it warns and takes them literally (_key_).
    • The schema-issue filter skips {key} as it skips {i}.
  • Runtime (ariadne.cpp): an instance's identity is a string key: the child's name, or the index under a count.
    • {key} is filled in through every field {i} already reaches: id, label, bind, on, the pointer handlers, the predicates, link: names and targets, name: and the rest of the §6.5 list. It also fills in app_name, for as: "{key}".
    • A repeated mount's sub-prefix is as: with its tokens filled in, else as: with the key appended (includes.<as>.<name>, as a count's includes.<as>.<i>). In the sub-prefix, a name's characters other than letters, digits, _ and - become _.
    • instance_path, mount_instances_ and the mount ticks are keyed by that string, and push_id takes the key. A child's backend id, sub-prefix, holes, init: and on_tick: resident therefore stay with it as siblings are added or removed.
    • A child taken out has its resident stopped and its instance freed at its repeat's next frame (sweep_repeated_ticks, which now also prunes mount_instances_; count repeats get the same pruning). Its state stays under its sub-prefix, as a quit application's does.
    • The Windows menu's repeated windows and the per-frame applications (plan_frame_apps) expand keyed repeats. A keyed mount with no name: is named by its child: tx_wtf for as: "{key}" with no meta.name, else Site tx_wtf.
  • Schema: a new widget_repeat def (a count, or {children: string}, closed) for widgets. Scene nodes keep the count-only repeat. ari validate follows.
  • Docs (ARIADNE.md): the map form and {key} (§6.5), a module per child of a key (§6.3), applications (§5.25), the sub-prefix (§7.3), when a resident stops (§7.4).
  • Example: examples/ariadne/documents/sites.ari mounts apps/site.ari per site, with Add and Remove.

Why this approach

  • Ariadne: the per-frame walk keeps its place on the heap, so any depth draws on a small stack #1577 (iterative walk, merged 04:44Z): this branch is on master with it. The change goes into its Op::Instances frame and begin_repeat, not the old recursive emit_node.
  • Ariadne shell SH1: mounts:, app-open/app-close, budgets per mount, shell.ari #1566 (SH1 mounts:, open): a trial git merge-tree of this branch with its head 124a59c merges all code without conflicts. The one conflict is a paragraph in ARIADNE.md §6.3, where both branches add text at the same place. The merged tree was not built.
  • Why not link: per entry on mounts::
    • SH1's mounts: loads a URI that each entry names in state. Each mount is sandboxed by its principal and budget, and no link: holes are granted by design.
    • Granting holes from those state-driven entries would let state choose what a module may reach. That would change SH1's security model, in a PR that is still open.
    • nicotina mounts the same document once per site, with the same grants, so a keyed load: fits that case. repeat: {children:} also works on plain widgets (a row per site) and grid cells.

Tests

New tests:

  • AriadneReactive.ARepeatOverAKeysChildrenNamesEachInstanceByItsChild: name order, {i}/{key}, backend ids by name; a child added first and one taken out; a missing key draws nothing.
  • AriadneReactive.ARepeatOverAKeysChildrenFillsAGridsCells: a cell per visible child.
  • AriadneMountScope.AMountRepeatedOverAKeysChildrenKeepsEachChildsInstance (a loaded fragment with init: and on_tick:): sites a and c, then b added and a taken out.
    • c keeps its local state, its init: doesn't run again, and its on_tick: resident keeps the same pid.
    • b's init: runs; a's resident is stopped and its state kept.
    • A write through c's hole lands on sessions.c.
  • AriadneRuntime.AMountRepeatedOverAKeysChildrenIsAnApplicationPerChild: menus named by child, by name: with {key}, and includes.<as>.<key>; Quit by name.
  • AriadneRuntime.WindowsMenuListsAWindowRepeatedOverAKeysChildren.
  • AriadneMount.ARepeatOverAKeysChildrenKeepsItsTokensForEachChild and AriadneMount.ARepeatOverChildrenThatIsMalformedWarns (loader and schema).
  • AriadneFtxui.AMountRepeatedOverAKeysChildrenDrawsARowPerChild: the FTXUI snapshot (what ari snapshot prints) of a keyed load: in one window. It checks the rows in name order, then that after a site is added first and one is removed, tx_wtf shows the note its init: wrote once and its visits through its hole.

Verified (Ubuntu 24.04, GCC, Release, FTXUI and tvision, cvcGL off)

Suite Result
ariadne_runtime_test 372 passed
ariadne_loader_test 274 passed (includes ShippedExamplesDeclareWhatTheyNeed)
ariadne_ftxui_test 127 passed
ariadne_schema_test 13 passed (includes EveryShippedDocumentIsValid)
ariadne_deep_nesting_test 12 passed
ariadne_host_test 66 passed
ariadne_chart_test, ariadne_settings_test 14, 11 passed
ctest -R ^ari_ 24/24 passed

ari validate passes sites.ari and apps/site.ari. ari snapshot draws sites.ari with a window per site (the terminal cascades them).

Not run here: cvcGL's ImGui backend and goldens, macOS, Windows, wasm (CI). Frame time wasn't measured. A count repeat now makes a string key per instance (it already made the string for push_id), and instance_path holds strings.

…y, named by it

A repeat over a key's children draws its template once per child, in name order, with {key}
the child's name wherever {i} is filled in today ({i} is its place). An instance is its child:
its backend id and a repeated mount's sub-prefix go by the name, so it keeps its state, its
init: and its on_tick: resident as siblings are added and taken out. A load: with
as: "{key}" mounts each child at includes.<name>, its link: targets, name: and handlers
filled in per child.

- loader: repeat: {children: key} on any widget (Widget::repeat_children); as: keeps its {i}
  and {key} tokens, and warns when no repeat: fills them in.
- runtime: an instance is keyed by a string (instance_path, mount_instances_, mount ticks);
  a mount instance whose child is gone has its resident stopped and its instance freed;
  the Windows menu and the per-frame applications expand keyed repeats too.
- schema: widget_repeat takes the map form (ari validate).
- docs/ARIADNE.md 6.3, 6.5, 5.25, 7.3, 7.4; examples/ariadne/documents/sites.ari.
- tests: runtime, loader and an FTXUI snapshot test.
…dren

# Conflicts:
#	docs/ARIADNE.md
#	src/cvc/ariadne/loader.cpp
Conflicts:
- docs/ARIADNE.md 6.3: the repeat section, then master's contributes:, shares:, grants: and
  application sections, then the closing paragraph on repeat versus mounts:.
- ariadne.cpp substitute_index_one: master's menu icons (SH10) and table rows/headers go
  through sub(), so they take {key} as well as {i}. The table copy is `tbl`, since `t` is the
  instance's tokens.
- The walk frame: master's comment on inst, plus the PR's keys.

Master's table rows (TableRows) now use the PR's string instance keys: the row index is
both {i} and {key}, as for a counted repeat. instance_path takes the string and autofocus
takes a pointer to it.
@transfix
transfix merged commit b02b334 into master Nov 30, 2026
31 checks passed
@transfix
transfix deleted the ariadne/repeat-children branch November 30, 2026 15:19
transfix added a commit that referenced this pull request Nov 30, 2026
A widget's repeat: takes {children: KEY}: an instance per child of the key, in name order, under
the child's name, {key} beside {i}. A repeated mount's scope goes by the child; {i} and {key} in
as: are kept for its instances, and warn and are taken literally without the repeat that fills
them in.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant