Domma Reactive User Manual

Keyed lists

Updated by Darryl Waterhouse on 17 October 2026 2 min read

{{#each items key=id}} reconciles. An item that stays in the collection keeps its DOM nodes and its effects across any change to the list, so focus, half-typed input, scroll position, CSS transitions and media playback all survive.

const data = {rows: [{id: 1, name: 'Ada'}, {id: 2, name: 'Grace'}]};

const controller = compile(
    '<ul>{{#each rows key=id}}<li>{{$index}}: {{name}}</li>{{/each}}</ul>',
    data, host
);

data.rows = [{id: 3, name: 'Katherine'}, ...data.rows];
controller.updateAll(data);
//  Ada's <li> is the same node object it was before. It was moved, not rebuilt.

key= names the property that identifies an item; a dotted path (key=meta.ref) works too. It must be an identity, not a value - a key that changes when the item's contents change defeats the whole mechanism.

Without key= the block falls back to re-rendering wholesale and says so once, naming the template. Nothing breaks; it simply costs you node identity. Pass {warnUnkeyed: false} in the compiler options to silence it.

What works inside a keyed block

Everything. Each item gets its own binding context and its own effects:

{{#each rows key=id}}
    <li data-bind-class="done && 'complete'">
        <input data-model="title">
        <button data-on-click="$parent.remove($data)">×</button>
        {{#if note}}<small>{{note}}</small>{{/if}}
        {{#each tags key=id}}<span>{{$parent.title}}/{{name}}</span>{{/each}}
    </li>
{{/each}}

$parent.remove($data) calls remove on the parent view model with the clicked row as its argument. That is the one place a method call is permitted in an expression - see data-on-<event>.

The renderer's loop variables ({{.}}, {{@index}}, {{@first}}, {{@last}}) resolve inside a keyed block too, so adding key= to an existing block never silently blanks anything.

One place key= is refused

A keyed block inside an unkeyed {{#each}} or a {{#with}} is demoted to an ordinary re-rendered block, with a warning. Its collection expression would otherwise be evaluated against the top-level data, where the name means nothing, and the list would render empty on a page that looks finished.

Add key= to the enclosing block and both reconcile - nesting keyed lists inside keyed lists is fully supported, to any depth.

Lifecycle

Each item is an instance: a pair of comment anchors, the nodes between them, a context, and one effect per binding. An instance is disposed - effects first, then nodes - when its key leaves the collection, when an enclosing region re-renders over it, or when the controller is destroyed.

Filtering and draft state

A key preserves an element only while its item stays in the rendered list. Filtering an item out removes its row. If an input draft must survive that removal, keep the draft on the item's view model as an observable and bind its .value.

Why keyed lists matter when someone is typing includes a live reordering example and explains this boundary.