Contents
- Welcome to Domma Reactive
- 01 Getting started
- 02 Reactive state
- 03 HTML and bindings
- 04 Components
- 05 Reference
Effects, subscriptions and batching
Updated by Darryl Waterhouse on 17 October 2026 · 1 min read
effect
const stop = effect(() => {
document.title = `${unread.value} unread`;
});
stop.dispose();
An effect runs immediately, so its dependencies are collected up front, and re-runs on the microtask flush after any of them changes. It sits at the leaves of the graph: nothing depends on an effect.
untracked(fn) suspends collection for the duration of fn, which is how an effect reads something it must not
subscribe to:
effect(() => {
const rows = list.value; // tracked
untracked(() => analytics.send(rows.length)); // not
});
subscribe
const off = count.subscribe(value => console.log('now', value));
count.value = 1; // logs immediately - no flush needed
off(); // or off.dispose(), for Knockout muscle memory
Subscribers fire synchronously, at the write, not on the flush that follows. You subscribed to a value, not to a
graph settling - so count.value = 5 followed by an assertion about the callback needs no flush.
They are not Computations, so a hundred subscriptions do not put a hundred nodes in the dependency graph. They follow
the same change gate: assigning a deeply equal value notifies nobody, and array mutators notify unconditionally.
A subscriber that throws is reported and skipped - one bad callback must not turn a write into an exception at an unrelated call site.
Batching and flushSync
Writes never recompute anything synchronously. They mark computations dirty, queue them, and schedule one microtask flush, so a burst of writes collapses into a single propagation pass and a single render:
first.value = 'Ada';
last.value = 'Lovelace';
age.value = 36;
// → one flush, one re-render
flushSync() drains the queue immediately and synchronously. It is what a test uses to assert on the DOM without
awaiting a microtask:
import {flushSync} from 'domma-reactive';
rows.push({id: 2});
flushSync();
expect(host.querySelectorAll('li')).toHaveLength(2);
On this page