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 <ui-bind> element prints it as it is.
<ui-component name="greeting" path="visitor.name" config="prefix:Hello"></ui-component>
<p>Stored value: <ui-bind path="visitor.name" config="text"></ui-bind></p>
<script>
COMPONENT('greeting', 'prefix:Hi', function(self, config) {
self.setter = function(value) {
self.text(config.prefix + ', ' + value + '!');
};
});
SET('visitor.name', 'Ana');
</script>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 |
| Flags | Change how a read or a write behaves, such as SET('price @nowatch', 5). | Flags and path modifiers |
| Data binding | Connects HTML elements to paths without writing JavaScript. | Data binding |
| Scopes | Give a part of the page its own base path. | Scopes |
| Virtual bindings | Render detached HTML and lists from a private model. | Virtual bindings |
| Components | Reusable UI pieces with their own behaviour. | Using 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, the template engine, with its
Thelpershelpers. - Routing for single-page applications, with
NAV,ROUTEandREDIRECT.
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 to build a working page with bound data and your own component.