Contents
- Welcome to Domma Reactive
- 01 Getting started
- 02 Reactive state
- 03 HTML and bindings
- 04 Components
- 05 Reference
Binding context and observable values
Updated by Darryl Waterhouse on 17 October 2026 · 2 min read
Binding context
Expressions resolve against a context, not a bare data object:
| Name | Meaning |
|---|---|
$data |
the object names resolve against |
$root |
the top-level data, however deep the nesting |
$parent |
the enclosing data (not the enclosing context) |
$parents |
all ancestor data, nearest first - $parents[0] is $parent |
$parentContext |
the enclosing context - the one name here that is one |
$index |
position within a list |
$length |
size of the enclosing list |
$component |
the enclosing component's view model |
All eight resolve everywhere. Outside a list or with block, $data and $root are the top-level data, $parents is
empty, and $parent, $parentContext, $index, $length and $component are null - so a binding never has to ask
where it is.
Pass plain data anywhere a context is accepted and it is promoted for you.
import {createRootContext, createChildContext} from 'domma-reactive';
const root = createRootContext({title: 'People'});
const child = createChildContext(root, {name: 'Ada'}, 0);
child.$parent.title; // 'People'
child.$index; // 0
There is no scope-chain walk: a bare name resolves against $data only. Reach a level up with $parent.name, which
says what it means.
Reaching further than one level
$parents is ancestor data, nearest first, so $parents[1] is a grandparent. $parentContext is the enclosing
context, which is how you reach a thing that is not data at all - the enclosing list's position:
<ul>{{#each groups key=id}}
<li>
<h3>{{name}}</h3>
<ol>{{#each members key=id}}
<li>
{{name}}
- in {{$parents[0].name}} <!-- the group: same as $parent.name -->
- of {{$parents[1].title}} <!-- the root: nothing else reaches it -->
- group {{$parentContext.$index}} <!-- the OUTER list's position -->
</li>
{{/each}}</ol>
</li>
{{/each}}</ul>
$parents is built only if a template asks for it, by walking $parentContext on first read, so a list that never
mentions the name pays nothing for it.
Both are frozen, as every context is. Writing to $parents[0] or to a context reached through $parentContext logs one
warning and does nothing - write to ancestor data instead, which $parents[1].name = x does.
An observable is not its value
A binding reads a value. data-if="show", where show is an observable(false), names the observable object itself -
and every object is truthy, so before 1.2 the content rendered and nothing said why. Now a binding whose expression
resolves to an observable, an observable array or a computed:
- warns once, naming the expression and the fix:
"show" is an observable, not its value - use "show.value"; - reads it as empty - fail closed:
data-ifand{{#if}}hide,data-bind-disabled/-hidden/-checkedare off, text and attributes are written as'', never"[object Object]".
The same holds when the observable is an operand: !show, count > 3, active && 'on'. The whole expression reads as
undefined - so !show cannot flip open either - with one warning naming the operand.
<p data-if="show">Never shown, with one warning</p>
<p data-if="show.value">Shown when show is true</p>
There is no automatic unwrapping, on purpose: one spelling, .value, everywhere. Two deliberate exceptions, where the
observable itself is what is wanted: a keyed list takes an observableArray directly ({{#each rows key=id}},
data-each="rows key=id"), and data-param-* passes whatever it is given to a component, by reference.