Domma Reactive User Manual

Custom bindings

Updated by Darryl Waterhouse on 17 October 2026 1 min read

registerBinding() adds a kind. It is not a side door: all ten built-ins are registered through this exact function, so anything a built-in does, a custom binding can do.

import {registerBinding, compile} from 'domma-reactive';

registerBinding('shout', {
    attribute: 'data-shout',   // or attributePrefix: 'data-shout-'
    expression: true,          // parse the value; binding.evaluate is set
    tracks: true,              // contribute the expression's deps
    primes: true,              // run update() once after the first paint
    update({binding, nodes, context}) {
        const value = String(binding.evaluate(context) ?? '');
        for (const el of nodes) el.textContent = value.toUpperCase() + '!';
        return true;
    }
});

compile('<p data-shout="name"></p>', {name: 'ada'}, host);   // → <p>ADA!</p>

update is required; attach({binding, node, controller}) and detach(…) are optional and are what data-on-* and data-model use to add and remove listeners. region: true wraps the owning element in comment anchors and fills binding.body, which is how data-if works. Register before compiling - a template already compiled does not pick up a new kind. The full contract is documented at the top of src/handlers.js.

The one thing a custom binding cannot do is invent {{ }} syntax: mustache is a fixed grammar, attributes are open-ended. Every handler is otherwise the same shape and dispatched by the same call.