Updater
The updater class connects an object with the dom
import { Updater } from "@schukai/monster/source/dom/updater.mjs";Introduction
The Updater connects a JavaScript object with the DOM and keeps both sides in sync using declarative attributes. When the object changes, the DOM is updated automatically; with event processing enabled, user input is written back into the object.
Quick Start
import { Updater } from "@schukai/monster/source/dom/updater.mjs";
const data = { headline: "Hello World" };
const updater = new Updater(document.body, data);
updater.run().then(() => updater.enableEventProcessing());
Core Attributes
| Attribute | Purpose |
|---|---|
data-monster-replace | Replaces element content with the pipe result (for example path:title). |
data-monster-attributes | Sets element attributes from pipe results (for example value path:price). |
data-monster-bind | Binds input values to a path (used by event processing and retrieve()). |
data-monster-bind-type | Casts bound values (for example number, boolean, string[], json). |
data-monster-insert | Clones a template for each item in an iterable (format: key path:items). |
data-monster-remove | Marks nodes that should be removed before re-inserting list items. |
data-monster-select-this | Forces attribute updates even if the direct value did not change (use sparingly). |
Binding and Input Sync
Use data-monster-bind for inputs and call enableEventProcessing() to write user input back to the subject. If you only need a one-time read, call retrieve().
Template Insertion
The insert feature clones a document template for each entry in a list and rewrites the internal paths so that nested bindings point to the correct item.
Simple Example
import { Updater } from "@schukai/monster/source/dom/updater.mjs";
const container = document.getElementById("updater-demo");
const data = {
headline: "Hello World"
};
const updater = new Updater(container, data);
updater.run().then(() => updater.enableEventProcessing());
const subject = updater.getSubject();
setTimeout(() => {
subject.headline = "Hello World!";
}, 1000);Exported
Updater, addObjectWithUpdaterToElementDerived from
BaseOptions
The Options listed in this section are defined directly within the class. This class is derived from several parent classes. Therefore, it inherits Options from these parent classes. If you cannot find a specific Options in this list, we recommend consulting the documentation of the Base.
Properties
The Properties listed in this section are defined directly within the class. This class is derived from several parent classes. Therefore, it inherits Properties from these parent classes. If you cannot find a specific Properties in this list, we recommend consulting the documentation of the Base.
Methods
The methods listed in this section are defined directly within the class. This class is derived from several parent classes. Therefore, it inherits methods from these parent classes. If you cannot find a specific method in this list, we recommend consulting the documentation of the Base.
Constructor
constructor(element,subject)1.8.0element{htmlelement}: elementsubject{object|proxyobserver|undefined}: subject
{TypeError}value is not a object{TypeError}value is not an instance of HTMLElement
Behavioral methods
disableEventProcessing()1.9.0- {Updater}
enableEventProcessing()1.9.0- {Updater}
{Error}the bind argument must start as a value with a path
updater.run().then(() => {
updater.enableEventProcessing();
});
Structural methods
getSubject()1.8.0- {Proxy}
setCallback(name,callback)name{string}: namecallback{function}: callback
- {Transformer}
{TypeError}value is not a string{TypeError}value is not a function
setEventTypes(types)1.9.0types{array}: types
- {Updater}
Other methods
retrieve()1.27.0- {Monster.DOM.Updater}
run()- {Promise}
updater.run().then(() => {
updater.enableEventProcessing();
});
undefined()- {Promise}
undefined(change)change
Events
This component does not fire any public events. It may fire events that are inherited from its parent classes.