Path
The properties and the methods of a parsed path.
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.
pathReturns String The clean path without flags.
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.
rawReturns String The path with its flags, without code lists.
property
flags
The flags of the path as an object.
flagsReturns 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.
splitReturns 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.
clReturns String The names of the code lists written with #, separated with a comma.
property
cache
The text written between < and >.
cacheReturns String The text written between < and >.
property
ERROR
Is true when the path contains the keyword ERROR.
ERRORReturns Boolean Is true when the path contains the keyword ERROR.
property
SYNC
Is true when the path contains the keyword SYNC.
SYNCReturns Boolean Is true when the path contains the keyword SYNC.
method
toString()
Returns the clean path.
toString()Returns String The path.
var path = new jComponent.Path('form.name @touched');
console.log(path.toString());
// logs: form.name
method
get(scope)
Reads the value at the path.
get(scope)| Parameter | Type | Description |
|---|---|---|
scope |
Object |
The object that the path is resolved against, usually window. |
Returns Object The value.
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.
set(scope, value)| Parameter | Type | Description |
|---|---|---|
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.
notify(scope, [flags])| Parameter | Type | Description |
|---|---|---|
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 }. |
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.
assign(path)| Parameter | Type | Description |
|---|---|---|
path |
String |
The relative path. |
Returns Path The new path.
The result depends on the first character of the argument:
| Argument | Result for form.user |
|---|---|
name | form.user.name |
@touched | form.user with the flag |
?suffix | form.usersuffix |
*name | common.name |
#name | DEF.cl.name |
%name | DEF.tmp.name |
Without an argument, the method returns the same object.
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.
includes(path, [partially])| Parameter | Type | Description |
|---|---|---|
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.
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.
exec(callback)| Parameter | Type | Description |
|---|---|---|
callback |
Function |
The function to call. |
Each flag is emitted as the event @flag name, with the path as the argument.
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.
find(scope, callback)| Parameter | Type | Description |
|---|---|---|
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.
<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>