Spanish Total.js
English
Documentation For AI agents
Contents

Path

The properties and the methods of a parsed path.

.md GitHub
On this page

A Path object holds a parsed path with its flags. It is available as component.path and plugin.path, and new jComponent.Path(path) creates one. The syntax of paths is explained in Paths and Flags and path modifiers.

API

property

path

The clean path without flags.

Returns String The clean path without flags.

Parse a path
var path = new jComponent.Path('form.user.name @touched #countries');
console.log(path.path);
// logs: form.user.name
console.log(JSON.stringify(path.flags));
// logs: {"touched":1}
console.log(path.cl);
// logs: countries
property

raw

The path with its flags, without code lists.

Returns String The path with its flags, without code lists.

property

flags

The flags of the path as an object.

Returns Object The flags of the path as an object.

A flag without a value has the value 1. The form @key:value keeps the value.

property

split

The path divided into its levels, from the first to the whole path.

Returns Array The path divided into its levels, from the first to the whole path.

property

cl

The names of the code lists written with #, separated with a comma.

Returns String The names of the code lists written with #, separated with a comma.

property

cache

The text written between < and >.

Returns String The text written between < and >.

property

ERROR

Is true when the path contains the keyword ERROR.

Returns Boolean Is true when the path contains the keyword ERROR.

property

SYNC

Is true when the path contains the keyword SYNC.

Returns Boolean Is true when the path contains the keyword SYNC.

method

toString()

Returns the clean path.

Returns String The path.

Convert to a string
var path = new jComponent.Path('form.name @touched');
console.log(path.toString());
// logs: form.name
method

get(scope)

Reads the value at the path.
ParameterTypeDescription
scope Object The object that the path is resolved against, usually window.

Returns Object The value.

Read and write in your own object
var path = new jComponent.Path('user.name');
var scope = {};
path.set(scope, 'Anna');
console.log(JSON.stringify(scope), path.get(scope));
// logs: {"user":{"name":"Anna"}} Anna
method

set(scope, value)

Writes a value at the path, without notifying anything.
ParameterTypeDescription
scope Object The object that the path is resolved against, usually window.
value Object The value to write.

Missing parent objects are created.

method

notify(scope, [flags])

Notifies the components, watchers and binders bound to the path.
ParameterTypeDescription
scope Object The object that the path is resolved against, usually window.
flags? String Flags as a string such as @touched, or as an object such as { touched: 1 }.
Notify the watchers
var path = new jComponent.Path('common.count');
WATCH('common.count', (value, flags) => console.log(value, JSON.stringify(flags)));
path.set(window, 5);
path.notify(window, '@touched');
// logs: 5 {"touched":1}
method

assign(path)

Creates a path relative to this one.
ParameterTypeDescription
path String The relative path.

Returns Path The new path.

The result depends on the first character of the argument:

ArgumentResult for form.user
nameform.user.name
@touchedform.user with the flag
?suffixform.usersuffix
*namecommon.name
#nameDEF.cl.name
%nameDEF.tmp.name

Without an argument, the method returns the same object.

Build relative paths
var path = new jComponent.Path('form.user');
console.log(path.assign('name').path);
// logs: form.user.name
console.log(path.assign('*name').path);
// logs: common.name
method

includes(path, [partially])

Tells whether two paths lie on the same branch.
ParameterTypeDescription
path String The path to compare.
partially? Boolean Compares the last level of the argument. Default: false

Returns Boolean The result of the comparison.

The result is true when one path is a parent of the other or both are the same. With partially, it is also true when a level of this path ends with the last level of the argument.

Compare paths
var path = new jComponent.Path('form.user');
console.log(path.includes('form'), path.includes('form.user.name'), path.includes('form.other'));
// logs: true true false
console.log(new jComponent.Path('form.user.name').includes('name', true));
// logs: true
method

exec(callback)

Emits the flags of the path, loads its code lists and calls a function.
ParameterTypeDescription
callback Function The function to call.

Each flag is emitted as the event @flag name, with the path as the argument.

Run the flags of a path
ON('@flag saved', path => console.log('flag', path));
new jComponent.Path('form.user @saved').exec(() => console.log('done'));
// logs: flag form.user
// logs: done
method

find(scope, callback)

Finds the ready components bound to the path.
ParameterTypeDescription
scope Object The object that the path is resolved against, usually window.
callback Function A function (components).

The flags @visible, @touched, @modified, @required, @invalid, @disabled and @enabled limit the result.

Find components in a form
<ui-component name="field" path="form.name"></ui-component>
<ui-component name="field" path="form.email"></ui-component>

<script>
COMPONENT('field', function(self) {});

new jComponent.Path('form').find(window, function(components) {
    console.log(components.map(m => m.path.toString()).join());
});
// logs: form.name,form.email
</script>
Made in Europe