DOCUMENTATION Docs Powered by Fuzor Docs

Lists and nested composition

A Fuzor list is ordinary HTML: a container, one inert <template>, and a key. The compiler renders the initial rows into the page, so they are there without JavaScript, and resumes them in the browser by key. This guide builds up from one list to nested lists whose rows hold components, Fuzor UI and server children. The snippets come from the maintained Fuzello /reactivity/ page and are tested in production builds. The reference lists every directive.

A keyed list

data-fz-each reads an array state cell of the containing native component. data-fz-key names the property that identifies a row; a row keeps its DOM, focus and unsaved field drafts while it moves.

<script type="module">
  const groups = fuzor.state("groups", [
    { id: "todo", title: "To do", children: [{ id: "same", title: "First task" }] },
    { id: "done", title: "Done", children: [{ id: "same", title: "Second task" }] }
  ])
  fuzor.action("reverse-groups", () => groups.update(rows => [...rows].reverse()))
</script>
<div class="nested-groups" data-fz-each="groups" data-fz-key="id"><template>
  <section class="nested-group">
    <h3><fz-item name="title"></fz-item></h3>
  </section>
</template></div>

Keys are local to their list. String "1" and number 1 are different keys, and a duplicate key is an error, not a silently dropped row. data-fz-key="." keys a list of strings or numbers by the value itself.

Nested lists

data-fz-item-each reads an array on the current row. Inside a row, data-fz-each still reads the owner's state, so the two never shadow each other.

<div class="nested-groups" data-fz-each="groups" data-fz-key="id"><template>
  <section class="nested-group">
    <h3><fz-item name="title"></fz-item></h3>
    <ul class="nested-tasks" data-fz-item-each="children" data-fz-key="id"><template>
      <li class="nested-task">…</li>
    </template></ul>
  </section>
</template></div>

Both groups above hold a task keyed same. They are separate rows with separate DOM and state, because a row's identity is its full path of keys, not its own key.

Row paths and ancestor reads

A row action receives context.event.rowKey (the innermost key) and context.event.rowPath, the outermost-to-innermost [range, key] pairs. Change the row the path names. Searching every group for a child id would also change the other same task.

fuzor.action("remove-task", context => {
  const [[, group], [, task]] = context.event.rowPath
  groups.update(rows => rows.map(row => row.id === group
    ? { ...row, children: row.children.filter(child => child.id !== task) }
    : row))
})

Range names in the path are compiler-owned; read only the keys. Item bindings read the innermost row; data-fz-item-depth="1" reads its parent instead:

<li class="child" data-fz-index="data-index">
  <fz-item name="."></fz-item>
  <b><fz-item name="label" data-fz-item-depth="1"></fz-item></b>
  <fz-index></fz-index>
</li>

<fz-index> shows the position. A position is never an identity.

Fragments, tables and forms

A template body may be empty or hold several sibling nodes; Fuzor marks the row boundaries with comments, so no wrapper element changes your layout. Use valid parent contexts: rows of <tr> in <tbody>, <option> in <select>:

<select data-fz-item-value="selected" data-fz-item-each="children" data-fz-key=".">
  <template><option data-fz-item-attr-value=".">Choice</option></template>
</select>
<table><tbody data-fz-item-each="children" data-fz-key="."><template>
  <tr><td data-fz-item-attr-title=".">Cell</td></tr><tr><td>Second row</td></tr>
</template></tbody></table>

data-fz-item-value and data-fz-item-checked bind fields to row values, and data-fz-item-attr-* binds safe attributes. A draft that differs from the last rendered value survives updates and moves; it is not saved into state for you.

Components inside rows

A component in a row gets the row as its props with data-fz-item-props="." (a dotted path passes a nested object instead). Each row's component is its own owner, with its own state, scripts and lifetime:

<li class="nested-task"><nested-task-card data-fz-item-props="."></nested-task-card>
  <button type="button" data-fz-click="remove-task">Remove task</button></li>
<script type="module">
  const steps = fuzor.state("steps", 0)
  const draft = fuzor.state("draft", fuzor.props.title ?? "")
  fuzor.action("step", () => steps.update(value => value + 1))
</script>
<article class="nested-card">
  <label>Task <input aria-label="Task title draft" data-fz-value="draft"></label>
  <button type="button" data-fz-click="step">Steps: <fz-state name="steps"></fz-state></button>
  <fuzor-select class="nested-status" data-fuzor-ui="select" value="planned">…</fuzor-select>
</article>

Moving a row moves its live component: steps, draft and the select's choice go with it. Removing a row disposes it and cancels its pending work; a row that comes back with the same key starts fresh. Rows inserted later, including into an empty list, get the same components. Module scripts, Fuzor UI roots and framework islands work inside rows too. React, Solid and Vue islands keep their roots and local state on moves and receive new props; their internal state is not part of Fuzor checkpoints.

Deferred Fuzor UI in rows needs a page-owned runtime. The demo starts one scoped to its component:

<script type="module">
  import { resumeUi } from "fuzor/ui/resume"
  const ui = resumeUi(host)
  onCleanup(() => ui.dispose())
</script>

The runtime starts when this script runs. A click on a UI control before that moment is not queued; one after it activates the control.

Lists generated by Fuzor UI

Fuzor UI owners expose their own read-only data under ui.: ui.items for select, combobox, listbox, async-list and table-of-contents, ui.children for a tree, ui.files for file upload. The template supplies the parts; the machine owns selection, highlighting, ARIA and focus.

<div data-part="content" data-fz-each="ui.items" data-fz-key="value"><template>
  <button data-part="item" data-fz-item-attr-data-value="value"
    data-fz-item-attr-disabled="disabled"><fz-item name="label"></fz-item></button>
</template></div>

The sources, keys and configuration rules are in compiled lists and machine data and restoration.

Server lists and row actions

A component with a leading <script server> serves the list from the server. Its row components may have server scripts of their own. Each is read on the server with props resolved from the current server row:

<script server type="text/typescript">
  import { defineServerData } from "fuzor/server"
  import * as Effect from "effect/Effect"
  import * as Reactivity from "effect/reactivity/Reactivity"
  import { readNestedVotes, voteNestedTask } from "../server/nested-list-store.ts"
  // props are resolved on the server from the current board row, never taken from the request.
  fuzor.action("server-vote", ({ props }) => Reactivity.mutation(Effect.sync(() => voteNestedTask(props?.group, props?.id)), ["nested-board"]))
  export default defineServerData(({ props }) => ({ votes: readNestedVotes(String(props?.group), String(props?.id)) }), { reactivityKeys: ["nested-board"] })
</script>
<script type="module">
  const draft = fuzor.state("draft", fuzor.props.title ?? "")
</script>
<article class="nested-card">
  <label>Note <input aria-label="Task note draft" data-fz-value="draft"></label>
  <button type="button" data-fz-click="server-vote">Server votes: <fz-state name="votes"></fz-state> +</button>
</article>

A vote changes one task. The action's POST answer carries the refreshed values, so there is no second request, and the note being typed stays in its field. An action on the parent list receives event.rowPath like a local action, but over the network that path is only a name: check it against your data and authorize the change. Fuzello's demo board is shared, process-local and resets on restart; it has no accounts or database.

Server code stays in the backend build. A build with server lists selects backend output automatically, while a page whose lists are all local still works as static files and in an inline SPA.

Checkpoints, limits and errors

snapshotNative and restoreNative save and restore declared native state by full row address. The checkpoint format is version 2 and the compiled manifest version 3; an older format is rejected, with no conversion. See explicit checkpoints.

Each list holds at most 2,048 rows, and one native owner at most 2,048 rows in total including nested lists. Lists and conditions nest at most eight levels deep. Row addresses have at most sixteen segments and string keys at most 256 characters. JSON, action and stream size limits still apply. Fuzor checks every changed list before touching the DOM: an invalid key or binding, or a batch over a limit, reports an error and leaves the page as it was. Fuzor does not virtualize long lists.

Built with Fuzor Back to top ↑
On this page Back to top ↑