Introduction
What jComponent is, the ideas it is built on and what the library includes.
jComponent is the client-side UI library of Total.js. You keep the data of your application in plain JavaScript objects, address that data with string paths and connect it to the page with custom HTML elements. When a value changes through the library, every element that depends on it updates itself.
There is no build step. A page needs one script and one stylesheet.
A first look
<p>Hello <ui-bind path="common.user" config="text"></ui-bind></p>SET('common.user', 'Ana');
// Later, from any place in your code:
setTimeout(function() {
SET('common.user', 'Peter');
}, 500);The page shows Hello Ana and, half a second later, Hello Peter. The code never touches the DOM: it writes a value to the path common.user, and the <ui-bind> element that listens to this path renders it.
The building blocks
| Concept | What it does | Guide |
|---|---|---|
| Path | A string such as app.user.name that addresses a value in the global window object | Paths |
| Flag | A word such as @change added to a path that changes how an operation behaves | Flags and path modifiers |
<ui-bind> | An element that renders a value of the model into the page | Data binding |
| Component | A reusable widget that reads a value from a path and can write it back | Using components, Creating components |
| Plugin | A block of application logic with its own part of the model | Plugins |
How data flows
- Your code calls
SET(), or a component writes a value that the user entered. - The library stores the value at the path, inside a normal JavaScript object.
- The library notifies everything that depends on the path: components,
<ui-bind>elements and watchers registered withWATCH(). - Each of them updates its own part of the page.
Because the model is a plain object, you can read it at any time, for example app.user.name in the browser console.
What the library includes
The file spa.min@20.js is a single bundle with everything a page needs:
- jComponent itself
- jQuery 3.7.1, available as
$ - Tangular, the template engine
- Routing for single-page applications, with
ROUTE(),REDIRECT()andNAV
The file spa.min@20.css contains a CSS reset, a responsive grid and helper classes such as hidden and invisible.
Where to go next
Follow Getting started to build a working page with a custom component and bound data. All functions are listed in the global functions reference.