Domma Reactive User Manual

Display and event bindings

Updated by Darryl Waterhouse on 17 October 2026 4 min read

Twelve binding kinds

Five come from mustache syntax:

Kind Template Updated by
text {{name}} textContent on a <span> anchor
attr class="{{cls}}" setAttribute on the owning element
block {{#if x}}…{{/if}} re-rendering a comment-delimited region
raw {{{html}}} re-rendering a comment-delimited region
each {{#each xs key=id}}…{{/each}} reconciling, per item - see below

Seven come from data-* attributes. Attributes rather than {{ }} because {{ }} produces a string, and events, two-way binding and focus all need a reference to a DOM element that survives rendering:

Attribute Purpose Example
data-on-<event> event binding, any DOM event data-on-click="save"
data-bind-<name> one-way to a property, class, style or attribute data-bind-text="user.name"
data-model two-way, control ↔ data data-model="query"
data-if conditional without a block data-if="isOpen"
data-options populate a <select> data-options="cities"
data-focus two-way, value ↔ focus data-focus="editing"
data-component render a registered component data-component="'contact-card'"

Every value on the right is an expression, not just a path.

data-on-<event>

The expression is either a reference that evaluates to a function, or a call:

<button data-on-click="save">Save</button>
<button data-on-click="remove(item, 2)">Delete</button>
<button data-on-click="$parent.remove($data)">Delete</button>

Your declared arguments come first and the event is always the last argument, so a handler that wants only the event and one that wants arguments are spelled the same way round. Returning false calls preventDefault().

The callee is resolved against your data, not against the helper registry - an event handler is a method on your data, and the evaluator is right to refuse to call one during a render.

A method call is allowed here and nowhere else. Inside a list $data is the item, and a bare name resolves against $data only, so $parent.remove($data) is how a row reaches the list that owns it. Everywhere else - {{ }}, data-if, data-bind-* - x.foo() is still a parse error, because those are reads that run inside an effect and a call during a read is a side effect. An event fires on a gesture, outside every effect.

this follows JavaScript's own rule, which is easier to remember than any rule this library could invent:

Expression this Why
save $data a reference; no receiver was named
save(x) $data a bare callee is a name on $data
handlers.save $data still a reference - nothing is called
handlers.save() handlers a method call keeps its receiver

The last two are exactly const f = o.m; f() versus o.m().

The method name is read through the same guard as every other property read, so $data.constructor() is refused for the same reason {{ $data.constructor }} is.

Event bindings declare no dependencies: the listener is attached once and reads the context at dispatch time, so there is nothing for an effect to re-run.

data-bind-<name>

The suffix is the target:

Suffix Effect
text textContent
class adds/removes only the tokens this binding applied last time
style an object of CSS properties - see below
style-<property> one CSS property, e.g. data-bind-style-font-weight
value checked disabled readonly required selected multiple indeterminate open hidden the DOM property
anything else an attribute of that name

For an attribute, false / null / undefined removes it and true sets it to the empty string, so data-bind-aria-hidden="collapsed" behaves the way you would expect rather than rendering the string "false".

data-bind-class is additive on purpose. el.className = value would delete every static class on the element, so the handler remembers the tokens it applied and swaps only those:

<p class="card" data-bind-class="isActive && 'on'"></p>

A falsy value contributes no classes at all, which is what makes that idiom work - isActive && 'on' is false, not '', when it is off.

There is no data-bind-html. Assigning innerHTML from data is the shortest route to a cross-site scripting (XSS) hole, and the template already has an explicit, greppable opt-out for it: {{{triple-stache}}}. Using the attribute logs one warning and writes nothing.

Style, in two spellings

<p data-bind-style-color="shade"></p>              <!-- one property   -->
<p data-bind-style-font-weight="weight"></p>       <!-- kebab-cased     -->
<p data-bind-style---brand="accent"></p>           <!-- custom property -->
<p data-bind-style="look"></p>                     <!-- {color, fontWeight, …} -->

Knockout writes style: {color: shade} because it compiles binding strings with the Function constructor. Since 1.2 this expression language parses plain object literals too (see Expressions), so data-bind-style="{color: shade}" works - but the single-property attribute stays the recommended spelling: it is the common case, it reads one property at a time, and the object case can equally take an object the view model already holds. In an object, camelCase keys are converted; in the attribute they are kebab-cased, because an HTML attribute name is lowercased by the parser and data-bind-style-fontWeight would arrive as fontweight.

A falsy value removes the property, so data-bind-style-color="isError && 'red'" works the way data-bind-class does. 0 is not treated as falsy here - opacity: 0 is a real value. Ownership follows the same rule as class: only the properties this binding set last time are removed, so a static style="margin: 4px" survives.

No unit is ever added. data-bind-style-width="w" with w = 40 sets width: 40, which the browser ignores; write w = '40px'.