Contents
- Welcome to Domma Reactive
- 01 Getting started
- 02 Reactive state
- 03 HTML and bindings
- 04 Components
- 05 Reference
Templates and rendering
Updated by Darryl Waterhouse on 17 October 2026 · 3 min read
compile() turns a mustache template into a set of fine-grained bindings, each owning a small region of the DOM. A
structural change re-renders only the block that changed - everything else keeps its node identity, so focus, scroll
position and unsaved input survive.
import {compile} from 'domma-reactive';
const host = document.querySelector('#out');
const controller = compile('<p>Hello {{name}}</p>', {name: 'Ada'}, host);
// → <p>Hello <span data-dm-t="0_txt">Ada</span></p>
controller.updateAll({name: 'Grace'}); // only the span is touched
compile(template, data, container, renderFn?, options?). Pass {reactive: true} and every binding gets its own
effect, collected from what it actually reads:
const name = observable('alice');
const controller = compile('<b data-bind-text="name.value"></b>', {name}, host, undefined, {reactive: true});
name.value = 'bob'; // the <b> follows, with nothing else to do
It is off by default because Domma wires its own. A standalone consumer almost certainly wants it on. Either way, list items always own their effects - nothing else is in a position to.
The controller:
bindings |
the binding records, each with id, kind, expr, deps |
deps(id) |
the root names one binding reads - how you subscribe an effect to exactly the right state |
update(id, data) |
re-run one binding |
updateAll(data) |
re-run all of them |
context() |
the binding context in force |
destroy() |
tear everything down |
compile(template, data, container, renderFn) still takes the mustache renderer as a parameter, and a caller who passes
one gets exactly that. The parameter is optional, and the default is renderTemplate, exported so you can use it on
its own:
import {renderTemplate} from 'domma-reactive';
renderTemplate('{{#each xs}}<li>{{name}}</li>{{/each}}', {xs: [{name: 'a'}]});
renderTemplate('{{> row}}', {n: 1}, {partials: {row: '<i>{{n}}</i>'}});
It supports {{x}}, {{{x}}}, {{#if}} / {{else}}, {{#unless}}, {{#each}}, {{#with}}, {{> partial}},
{{.}}, {{@index}}, {{@first}}, {{@last}} and {{! comments }}. Interpolations escape; triple-staches do not.
Divergences from Domma's utils.render
Domma passes its own utils.render and is unaffected by any of this. But the two are not identical, and the
differences below were verified against utils.render at Domma v0.33.1 rather than assumed:
| Case | Domma's utils.render |
renderTemplate |
|---|---|---|
Same-kind nesting - {{#each}} inside {{#each}} |
matches the inner {{/each}}, producing broken output |
counts depth; correct |
{{else}} inside a nested {{#if}} |
binds to the outer block | binds to its own block |
{{.}} over a list of primitives |
[object Object] |
the item |
Expressions - {{ n > 1 ? 'many' : 'one' }} |
empty | evaluated |
{{#if n > 2}} |
always falsy | evaluated |
{{helper arg}} (space-separated) |
calls a registered helper | not supported - renders empty, no warning. Use helper(arg) |
Escaping, missing values, {{#each}} item scope, {{@index}}, {{#with}}, kebab-case keys |
identical |
The first four rows are cases Domma's renderer does not handle correctly and this one does, so a template that works
under Domma works here. The reverse is not guaranteed - an expression or a nested same-kind block written against
this renderer will not survive a move to utils.render.
Expressions in {{ }}, and what the compiler binds
A {{ }} becomes a live text binding when it is a dotted path, or when it contains unambiguous operator syntax and
parses. {{.}}, {{@index}} and {{helper arg}} are left to the renderer, and never warn.
- and + count as operators only with whitespace around them, so {{first-name}} reads a kebab-case key and
{{ a - b }} is arithmetic.
An expression interpolation is evaluated once immediately after the first paint, because the injected renderer may not
understand it. data-bind-*, data-model and data-if are primed the same way, for the same reason: there is no
{{ }} token in an attribute for a renderer to substitute.
{{{raw}}} and class="{{cls}}" still go through the renderer and still accept dotted paths only. Use data-bind-*
for an expression-valued attribute.