Domma Reactive User Manual

Conditions and virtual bindings

Updated by Darryl Waterhouse on 17 October 2026 2 min read

data-if

The element is in the DOM, or it is not - it is not hidden with CSS. A binding named after a conditional that leaves the element focusable and read by a screen reader would be lying; use data-bind-hidden if that is what you want.

<div data-if="isOpen">…</div>

Truthiness is mustache truthiness, so an empty array is falsy and {{#if items}} and data-if="items" cannot disagree. Read the observable's value - data-if="isOpen.value" when isOpen is an observable. Naming the observable itself is caught: see An observable is not its value. Toggling re-renders the element rather than stashing and restoring it, so bindings inside it can never go stale - at the cost of node identity across a toggle, exactly as {{#if}} has always behaved.

Virtual bindings, for markup with no element to spare

A binding attribute needs an element to sit on. Sometimes there is none to spare - a run of <li>s, three <td>s in a row, a fragment inside a <p> - and wrapping them in a <div> to carry the attribute changes the layout, or inside a table is not even valid HTML a browser will keep. Comments have no such problem.

<ul>
    <li>Always shown</li>
    <!-- dm if: showExtras -->
        <li>Only when showExtras</li>
        <li>These two travel together</li>
    <!-- /dm -->

    <!-- dm each: rows key=id -->
        <li data-bind-text="name"></li>
    <!-- /dm -->
</ul>

<p>Signed in as <!-- dm text: user.name -->…<!-- /dm -->.</p>

This is Knockout's <!-- ko if: x --> … <!-- /ko -->, and it is the one thing applyBindings genuinely could not express. compile() has never needed it, because {{#if}} already delimits a region with comments of its own - so these exist only for markup that arrived from a server, where the author cannot add mustache.

Form Behaviour
<!-- dm if: expr --> the run of nodes is in the document, or held aside - the same nodes come back, with their listeners and their focus
<!-- dm each: expr key=id --> the run is the item template, lifted and compiled exactly as data-each is; key= is required for the same reason
<!-- dm text: expr --> one text node between the anchors, replacing whatever the server put there as a placeholder

Every closer is <!-- /dm -->, whatever it closes. They nest, and a block held out of the document keeps its nodes' sibling relationships, so a nested block that changes while its parent is closed still lands correctly when the parent reopens.

Two limits, both warned about rather than silent: an opener with no <!-- /dm --> is skipped, and a virtual binding inside a virtual list's body is not read - that body is compiled as a template, and the compiler knows mustache, not comments. Its content is left out of every row (fail closed: before 1.2 it rendered unconditionally, so a hidden <!-- dm if --> showed in every row). Use {{#if flag}} inside a list body - it is scoped to the item - or data-if on an element.