--- title: Introduction project: jComponent V19 version: 19.194 section: guides language: en license: MIT url: https://totaljs.es/docs/jcomponent-v19/19-194/guides/introduction/ updated: 2026-11-18T13:55:44.124Z --- # Introduction > What jComponent is, the ideas it is built on and what the library file contains. jComponent is the client-side UI library of Total.js. You build a page from reusable components and plain HTML elements, and all of them read and write one shared data model. When a value in the model changes, everything that depends on it updates by itself. There is no build step. You load one JavaScript file and one stylesheet, and the page works. ## A first look This page shows one value in two places. A component formats it, and a `` element prints it as it is. ```html

Stored value:

``` The page renders `Hello, Ana!` and `Stored value: Ana`. Calling `SET('visitor.name', 'Ben')` later changes both to the new name. Neither the component nor the element knows about the other: they only share the path `visitor.name`. ## The main ideas | Idea | What it does | Guide | | --- | --- | --- | | Paths | Name a place in the data model, such as `order.address.city`. | [Paths](../paths/) | | Flags | Change how a read or a write behaves, such as `SET('price @nowatch', 5)`. | [Flags and path modifiers](../flags/) | | Data binding | Connects HTML elements to paths without writing JavaScript. | [Data binding](../data-binding/) | | Scopes | Give a part of the page its own base path. | [Scopes](../scopes/) | | Virtual bindings | Render detached HTML and lists from a private model. | [Virtual bindings](../virtual-bindings/) | | Components | Reusable UI pieces with their own behaviour. | [Using components](../using-components/), [Creating components](../creating-components/) | ## What the library file contains The file `spa.min@19.js` is self-contained. Besides jComponent it includes: - jQuery 3.6.0, available as `$`. - [Tangular](../tangular/), the template engine, with its `Thelpers` helpers. - [Routing](../routing/) for single-page applications, with `NAV`, `ROUTE` and `REDIRECT`. The stylesheet `spa.min@19.css` contains the `.hidden` and `.invisible` classes that the binding commands `show`, `hide`, `visible` and `invisible` rely on, so load it on every page. The value of `MAIN.version` is the number of the running release, `19.194`. ## Where to go next Follow [Getting started](../getting-started/) to build a working page with bound data and your own component. --- title: Getting started project: jComponent V19 version: 19.194 section: guides language: en license: MIT url: https://totaljs.es/docs/jcomponent-v19/19-194/guides/getting-started/ updated: 2026-11-18T18:15:26.748Z --- # Getting started > Build a working page with bound data and a custom component, starting from an empty HTML file. This guide takes you from an empty file to a page with bound data and two custom components. You only need a text editor and a browser. ## Load the library Create a file named `index.html` and load the script and the stylesheet in the ``: ```html My first page ``` Every snippet in the next steps goes inside ``. ## Show a value Data lives at [paths](../paths/). `SET()` writes a value, and the `` element displays it: ```html

``` The heading shows `My first page`. The `path` attribute says which value to read, and `config="text"` says to write it as the text of the element. If you run `SET('page.title', 'Changed')` in the browser console, the heading changes immediately. [Data binding](../data-binding/) lists everything `` can do. ## Create a component A component is declared once with `COMPONENT()` and placed with `` as many times as you need. This one renders a labelled text box: ```html ``` - `'label:Text'` is the default configuration. The `config` attribute of the element overrides it. - `self.make` runs once and builds the content of the element. - `data-jc-bind` connects the input to the path of the component. Typing `Ana` into the box stores `{"name":"Ana"}` in `form`, and writing to `form.name` updates the box. ## Add behaviour Components often need their own logic. The `counter` component below draws a button and writes to its path through `self.set()`. Its `self.setter` function runs each time the value at the path changes, so the screen always follows the data. ```html ``` ## The complete page Put everything together. This is the whole file: ```html My first page

``` Open the file in a browser. The summary line stays hidden until you type a name, because `show:value` hides the paragraph while `form.name` is empty. If you type `Ana` and press the button twice, the page shows `Ana booked 3 ticket(s)`. The counter stops at `5`, the value of `max` in the `config` attribute. ## Run code when the page is ready The `ready` event fires once the components on the page are initialized. It needs at least one component on the page. ```html ``` ## Next steps - Learn how values are addressed and who is notified of a change in [Paths](../paths/). - Connect more of your page with [Data binding](../data-binding/). - Give each part of the page its own data with [Scopes](../scopes/). - Go deeper into the component API in [Creating components](../creating-components/). --- title: Paths project: jComponent V19 version: 19.194 section: guides language: en license: MIT url: https://totaljs.es/docs/jcomponent-v19/19-194/guides/paths/ updated: 2026-11-18T13:55:44.124Z --- # Paths > How paths address values in the data model, how to read and write them, and who is notified of a change. A path is a string that names a place in the data model, such as `order.address.city`. Components, bindings and your own code all use paths to share data. By default a path starts at the `window` object, so `order.address.city` is the same value as `window.order.address.city`. ## Read and write values [SET()](../../reference/globals/) writes a value and [GET()](../../reference/globals/) reads it. Missing objects and arrays on the way are created for you, and reading a path that does not exist returns `undefined` without an error. ```js SET('shop.cart.total', 120); console.log(window.shop); // {"cart":{"total":120}} console.log(GET('shop.cart.total')); // 120 console.log(GET('shop.order.total')); // undefined SET('shop.items[1].name', 'Keyboard'); console.log(shop.items); // [null,{"name":"Keyboard"}] ``` ## Helpers for common changes These functions change a value and notify everything that depends on it: ```js SET('cart', { count: 1, items: [], open: false, note: 'gift' }); INC('cart.count'); // 2 INC('cart.count', 3); // 5 PUSH('cart.items', 'tea'); // ["tea"] EXT('cart', { city: 'Rome' }); // adds cart.city and keeps the other fields TOGGLE('cart.open'); // true NUL('cart.note'); // null console.log(cart); // {"count":5,"items":["tea"],"open":true,"note":null,"city":"Rome"} WATCH('cart.count', (path, value) => console.log('changed', value)); cart.count = 10; // no notification UPD('cart.count'); // changed 10 ``` | Function | What it does | | --- | --- | | `SET(path, value)` | Replaces the value. | | `INC(path, [value])` | Adds `value` to a number. The default is `1`. | | `PUSH(path, value)` | Adds an item, or every item of an array, to an array. | | `EXT(path, object)` | Copies the fields of `object` into the object at the path. | | `TOGGLE(path)` | Inverts a boolean. | | `NUL(path)` | Sets the value to `null`. | | `UPD(path)` | Keeps the value and notifies its dependents. | Assigning to a variable directly, as in `cart.count = 10`, changes the value silently. Call `UPD()` afterwards to announce the change. ## Delay a write A number of `10` or more as the third argument of `SET()` delays the write by that many milliseconds. Calling it again for the same path within the delay replaces the pending write. ```js SET('delayed.value', 1, 100); console.log(window.delayed); // undefined setTimeout(() => console.log(delayed.value), 200); // 1 ``` ## Path prefixes A prefix sends the path to a dedicated storage object: | Prefix | Stored in | Use it for | | --- | --- | --- | | `%` | `jctmp` | Temporary values. | | `*` | `common` | Values shared across the application. | | `#` | `DEF.cl` | Code lists, such as the options of a select box. | ```js SET('%wizard.step', 2); console.log(jctmp.wizard.step); // 2 SET('*user', 'Ana'); console.log(common.user); // Ana SET('#colors', ['red', 'green']); console.log(DEF.cl.colors); // ["red","green"] console.log(GET('%wizard.step'), GET('*user'), GET('#colors')); // 2 Ana ["red","green"] ``` ## Who is notified of a change A change at a path notifies its parents and its children. Paths on other branches are left alone. ```js WATCH('order', (path, value) => console.log('order <-', path)); WATCH('order.address', (path, value) => console.log('address <-', path)); WATCH('order.address.city', (path, value) => console.log('city <-', path)); WATCH('order.note', (path, value) => console.log('note <-', path)); SET('order.address.city', 'Madrid'); // order <- order.address.city // address <- order.address.city // city <- order.address.city SET('order.address', { city: 'Lisbon' }); // order <- order.address // address <- order.address // city <- order.address ``` Writing to `order.address.city` reaches the watchers of `order`, `order.address` and `order.address.city`. The watcher of `order.note` stays silent in both writes. The same rule applies to components and to [bindings](../data-binding/). ## Watch a path [WATCH()](../../reference/globals/) calls a function when a path changes. The function receives the path that changed, the current value at the watched path and the type of the change. Pass `true` as the third argument to run it immediately with the current value. ```js WATCH('stock.count', function(path, value, type) { console.log(path, value, type); }, true); // stock.count undefined 0 SET('stock.count', 5); // stock.count 5 1 ``` | Type | Meaning | | --- | --- | | `0` | The initial value. | | `1` | Changed by code. | | `2` | Changed by user input. | | `3` | Set to the default value. | ## Fixed paths A `!` in front of a watched path ignores changes that happen below it. The watcher still reacts to the path itself and to its parents. ```js WATCH('order.address', () => console.log('normal')); WATCH('!order.address', () => console.log('fixed')); SET('order.address.city', 'Madrid'); // normal SET('order.address', { city: 'Rome' }); // normal, fixed SET('order', { address: {} }); // normal, fixed ``` ## Environment values A name in square brackets is replaced by the value stored with [ENV()](../../reference/globals/): ```js ENV('tenant', 'acme'); SET('data.[tenant].plan', 'pro'); console.log(window.data); // {"acme":{"plan":"pro"}} ``` ## Plugin paths The form `name|property` addresses a property of a [plugin](../plugins/). To read a value you can also write `name/property`. ```js PLUGIN('cart', function(exports) { exports.total = 10; }); setTimeout(function() { console.log(GET('cart|total')); // 10 SET('cart|total', 25); console.log(PLUGINS.cart.total); // 25 console.log(GET('cart/total')); // 25 }, 200); ``` ## Paths relative to a scope Inside a scope, the `?` character stands for the path of the scope, so `?.name` can point to a different value in each part of the page. [Scopes](../scopes/) explains how this works. --- title: Flags and path modifiers project: jComponent V19 version: 19.194 section: guides language: en license: MIT url: https://totaljs.es/docs/jcomponent-v19/19-194/guides/flags/ updated: 2026-11-18T13:55:44.124Z --- # Flags and path modifiers > Change how a read or write behaves by adding flags and modifiers to a path. A path can carry extra instructions. Flags start with `@` and follow the path after a space, as in `SET('price @nowatch', 5)`. Path modifiers are characters that change what the operation does, as in `SET('+tags', 'red')`. Several flags can be combined in one path. ## Flags for the state of components Components keep track of whether the user `touched` or `modified` them. These flags set that state while writing the value: | Flag | Effect on the components at the path | | --- | --- | | `@touch` | Marks them as touched. | | `@change` | Marks them as touched and modified. | | `@modify` | Marks them as touched and modified. | | `@reset` | Clears touched and modified. | | `@default` | Writes the default value of each component and clears touched and modified. | ```html ``` ## Flags for notifications | Flag | Effect | | --- | --- | | `@nowatch` | Does not call the watchers of the path. | | `@type:N` | Reports the number `N` as the type of the change. | | `@diff` | Skips the write when the new value equals the current one. | ```js WATCH('price', (path, value, type) => console.log('watch', value, type)); SET('price', 10); // watch 10 1 SET('price @nowatch', 20); // (no output) SET('price @type:5', 30); // watch 30 5 SET('price @diff', 30); // (no output, the value is the same) SET('price @diff', 40); // watch 40 1 ``` The flag `@nobind` works with [REWRITE()](../../reference/globals/), which stores a value without updating components. With the flag, bindings are not updated either: ```html ``` ## Flags for reading | Flag | What `GET()` does | | --- | --- | | `@clone` | Returns a copy of the value. | | `@modified` | Returns an object with only the fields whose components are touched and modified, or `null` when there are none. | | `@reset` | Returns the value and clears the state of the components at the path. | | `@update` | Returns the value and then notifies the dependents of the path. | ```html ``` ```js WATCH('stock', (path, value) => console.log('watch', value)); window.stock = 5; console.log(GET('stock @update')); // 5 // watch 5 ``` ## Custom flags Any other name is a custom flag. Listen for it with `ON('@flag name', fn)`. The function receives the path, the value and the type. Custom flags also work with `EXEC()` and `EMIT()`, where the path argument is the name that was called. ```js ON('@flag audit', function(path, value, type) { console.log('audit:', path, value); }); function ping() {} SET('invoice.total @audit', 90); // audit: invoice.total 90 GET('invoice.total @audit'); // audit: invoice.total 90 EXEC('ping @audit'); // audit: ping undefined EMIT('saved @audit'); // audit: saved undefined ``` ## Add to arrays and merge objects | Syntax | Effect | | --- | --- | | `SET('+path', value)` | Adds the value to the array, like `PUSH()`. | | `PUSH('^path', value)` | Adds the value to the start of the array. | | `SET('~path', object)` | Merges the object into the current value, like `EXT()`. | | `SET('path @extend', object)` | Merges the object as well. | ```js SET('+tags', 'red'); SET('+tags', 'green'); console.log(tags); // ["red","green"] PUSH('^tags', 'first'); console.log(tags); // ["first","red","green"] SET('user', { name: 'Ana', age: 30 }); SET('~user', { age: 31 }); console.log(user); // {"name":"Ana","age":31} SET('user @extend', { city: 'Rome' }); console.log(user); // {"name":"Ana","age":31,"city":"Rome"} ``` ## Transform a value An arrow after the path runs an expression on the value. Both `-->` and `->` work. With `SET()` the result is stored, and with `GET()` the result is returned while the stored value stays the same. The expression must use the word `value`. The same syntax works in the `path` attribute of ``. ```html ``` ## Wait for a code list A `#name` after the path postpones the write until the code list `name` is loaded. Code lists are declared with [CL_INIT()](../../reference/globals/). ```js CL_INIT('colors', function(next) { setTimeout(() => next(['red', 'green']), 100); }, true); SET('form.color #colors', 'red'); console.log(window.form); // undefined setTimeout(function() { console.log(form.color, DEF.cl.colors); // red ["red","green"] }, 300); ``` --- title: Data binding project: jComponent V19 version: 19.194 section: guides language: en license: MIT url: https://totaljs.es/docs/jcomponent-v19/19-194/guides/data-binding/ updated: 2026-11-18T13:55:44.124Z --- # Data binding > Connect HTML elements to paths with ui-bind and data-bind, without writing JavaScript. Data binding connects an HTML element to a [path](../paths/). When the value changes, the element updates by itself. You describe what should happen with short commands, and most pages need no extra JavaScript for it. ## The ui-bind element `` takes the path in the `path` attribute and a list of commands in the `config` attribute. Commands are separated by a semicolon, and each one has the form `command:value`. ```html

``` The four paragraphs show `Ana`, `ANA`, `user.name = Ana` and `Ana!`. The part after the colon can take these forms: | Form | Example | Result | | --- | --- | --- | | Nothing | `text` | The value itself. | | Expression | `text:value.toUpperCase()` | The result of the expression. | | Arrow function | `text:(value, path) => path + value` | The return value. It also receives the element as the third argument. | | Function name | `text:shout` | The return value of the global function `shout(value, path, element)`. | An expression must contain the word `value`. Text without it is read as the path of a function, so a fixed string such as `text:'Hello'` is not valid. ## Bind any element The `data-bind` and `bind` attributes add a binding to an existing element. The path and the commands are separated by two underscores. ```html
``` ## Show and hide elements | Command | When the result is true | CSS class it uses | | --- | --- | --- | | `show` | The element is displayed, otherwise it is hidden. | `hidden` | | `hide` | The element is hidden. | `hidden` | | `visible` | The element is visible, otherwise it keeps its space but cannot be seen. | `invisible` | | `invisible` | The element keeps its space but cannot be seen. | `invisible` | A command that starts with a dot toggles that CSS class. ```html Your cart is empty Checkout Status ``` With a count of `0`, the first element is hidden, the second shows its text, the third is invisible and the fourth has the class `empty`. With a count of `3`, the first shows `3 items` and the fourth has the class `full`. ## Update child elements Add a CSS selector after the command to apply it to the elements inside the binding. ```html Administrator ``` The result is `Ana Engineer Administrator`, and the `` element receives `data-id="7"`. ## Content, attributes and form controls | Command | Effect | | --- | --- | | `text` | Sets the text. | | `html` | Sets the HTML. | | `value` | Sets the value of a form control. | | `checked` | Checks or unchecks a checkbox. | | `disabled` | Disables the element when the result is true. | | `enabled` | Enables the element when the result is true. | | `title` | Sets the `title` attribute. | | `href` | Sets the `href` attribute. | | `src` | Sets the `src` attribute. | | `attr name` | Sets the attribute `name`. | ```html ``` On a `` element, `disabled` and `enabled` apply to the components, inputs, text areas, select boxes and buttons inside it. ## Render a template The `template` command renders a [Tangular template](../tangular/) placed in a ` ``` ## React to clicks and changes `click` calls a function with the element, the event, the current value and the path. `exec` calls a function each time the value changes. ```html ``` ## Format the output | Command | Effect | | --- | --- | | `format:2` | Formats a number with that many decimals. | | `format:yyyy-MM-dd` | Formats a date. | | `empty` | Shows `---` for an empty value. | | `empty:text` | Shows `text` for an empty value. | | `default:expression` | Uses the result of the expression when the value is `null` or `undefined`. | A `!` in front of a command skips it while the value is `null` or `undefined`, so the original content of the element stays visible. ```html

Loading

``` The paragraphs show `1 234.50`, `2026-01-15`, `---`, `Nothing yet`, `Not set` and `Loading`. ## Control when a binding updates | Command | Effect | | --- | --- | | `track:a,b` | On a binding to an object, reacts only to changes of the listed fields. | | `strict` | Ignores changes made to paths below the bound path. | | `once` | Runs one time only. | | `changes` | Runs only when the value differs from the previous one. | | `delay:300` | Waits this many milliseconds. | ```html ``` ## Update hidden elements Commands that change the content are skipped while `show`, `hide`, `visible` or `invisible` keep the element hidden, and they run again when it appears. A `~` in front of a command runs it anyway. ```html ``` While the box is closed, the first element is empty and the second already contains `Hello`. ## Target another element The `element` attribute applies the binding to any element selected with a CSS selector. The `child` attribute applies it to an element inside the binding. ```html Name: ``` ## Pass values to a component `set` sends a value to a component inside the binding, and `config` reconfigures it. Both are useful for a component that has no path of its own. ```html ``` The component renders `RED (red)`. ## Two-way binding Bindings only write to the page. To send user input back to the model, use a component with an input marked with `data-jc-bind`. Typing `Ben` in this box changes `profile.name`, and the paragraph follows. ```html

Hello

``` [Creating components](../creating-components/) describes how inputs work inside components. --- title: Scopes project: jComponent V19 version: 19.194 section: guides language: en license: MIT url: https://totaljs.es/docs/jcomponent-v19/19-194/guides/scopes/ updated: 2026-11-18T13:55:44.124Z --- # Scopes > Give a part of the page its own base path, so the same markup can work with different data. A scope gives a part of the page its own base path. Inside it, the `?` character stands for that path. The same markup can then be reused with different data, and a block of the page does not need to know where its data is stored. ## Create a scope Wrap the markup in a `` element and start the inner paths with `?`. ```html ``` The first block shows `Ana billing.vat = A1` and the second `Ben shipping.vat = B2`. Using `?` outside a scope is an error: the browser console shows the warning `Missing ` and the binding is not created. ## Nested scopes A scope inside another scope extends the path of its parent. A `!` in front of the name makes the scope isolated, so it ignores the parent. `?1` refers to the parent scope, `?2` to the parent of the parent, and so on. ```html ``` | Element | Path of the scope | | --- | --- | | `` | `order` | | `` inside it | `order.address` | | `` inside it | `shared` | In the example `?.city` reads `order.address.city`, and `?1.ref` reads `order.ref`. ## Configure a scope | Attribute or setting | Effect | | --- | --- | | `path="?"` | Generates a unique name for the scope. | | `default="{ ... }"` | Stores this value at the path of the scope when the scope is created. | | `config="init:name"` | Calls the global function `name(path, element)` when the scope is created. | | `config="aclass:1"` | Adds the path of the scope as a CSS class on the element. | | `config="class:name"` | Toggles a CSS class on the element shortly after it is created. | ```html ``` The second scope stores `{"user":"guest","remember":false}` in `login`, and its element receives the classes `login` and `ready`. ## Use an existing element as a scope The attributes `scope`, `plugin` and `data-scope` turn any element into a scope. ```html
``` ## Work with a scope in code `$(element).scope()` returns the scope that an element belongs to. Paths given to its methods are relative to the scope. ```html ``` | Member | Description | | --- | --- | | `path` | The full path of the scope. | | `element` | The element of the scope, as a jQuery object. | | `parent` | The parent scope. | | `makepath(path)` | Replaces `?` with the path of the scope. | | `get([path])` | Reads a value. Without a path it returns the whole object. | | `set(path, value)` | Writes a value. | | `push(path, value)` | Adds a value to an array. | | `update(path)` | Notifies the dependents of a path. | | `watch(path, fn, [init])` | Watches a path. | | `FIND(selector)` | Finds a component inside the scope. | | `SETTER(selector, method, ...)` | Calls a method of the components inside the scope. | The [Scope](../../reference/scope/) reference lists all the members. ## Connect a plugin A [plugin](../plugins/) with the same name as the scope holds the logic of that part of the page. Inside the scope, `?/name` refers to a function of the plugin, and `?` in the code of the plugin stands for its path. ```html ``` The label shows `ANA`. Clicking the button prints `saving Ana from contact.name` and stores `true` in `contact.saved`. --- title: Virtual bindings project: jComponent V19 version: 19.194 section: guides language: en license: MIT url: https://totaljs.es/docs/jcomponent-v19/19-194/guides/virtual-bindings/ updated: 2026-11-18T13:55:44.124Z --- # Virtual bindings > Render detached HTML and repeated rows from a private model, outside the global data. A virtual binding connects a piece of HTML to a private model instead of a global [path](../paths/). It suits repeated content such as table rows, list items and cards, where each item has its own data. ## Bind a piece of HTML [VBIND()](../../reference/globals/) creates the HTML and returns a binder object. Paths inside it start with a dot and are relative to the model. A dot alone stands for the whole model. The commands are the same as in [Data binding](../data-binding/). ```html
``` The binder is not attached to the page by itself. Add `card.element`, a jQuery object, wherever you need it. ## Update the model ```html
``` | Member | Description | | --- | --- | | `element` | The HTML of the binder, as a jQuery object. | | `set(model)` | Replaces the model and redraws all bindings. | | `set(path, value)` | Changes one field and redraws the bindings that depend on it. | | `get([path])` | Reads the model or one field. | | `upd([path])` | Redraws after you changed the model directly. | | `on(event, [selector], fn)` | Adds an event listener to the element. | | `remove()` | Removes the element and its listeners. | ## Handle events and remove the binder ```html
``` ## Render a list [VBINDARRAY()](../../reference/globals/) repeats one template for each item of an array and appends the rows to a target element. Each row receives a `data-index` attribute. When you set a new array, existing rows are reused, extra rows are removed and only rows whose data changed are redrawn. ```html
    ``` | Member | Description | | --- | --- | | `items` | The binders of the rows. | | `set(array)` | Renders the array. | | `set(index, item)` | Replaces one row. | | `get([index])` | Reads the array or one item. | | `upd([index])` | Redraws one row, or every row, after you changed the data directly. | | `remove()` | Removes all rows. | ## Bind a list to a path The `vbindarray` command connects a list to a global path. Put the row in a `