Class: Route

Route.Route(root)

new Route(root)

A class for selecting and assigning values in a data model.

Parameters:
Name Type Description
root *

The root Route or data model this route is based on.

Source:
Example
```javascript
var model = { a: { b: { c: 'value' } } };
var route = Route.select(model, ['a', 'b', 'c']);
JSON.stringify(route.data); // { c: 'value' }
console.log(route.index); // 'c'
console.log(route.result); // 'value'
```

```javascript
var model = { x: { y: { z: 'value' } } };
var route = Route.select(model, ['a', 'b', 'c']);
[...route].map(node => node.name).join(', '); // null, 'a', 'b', 'c'
[...route].map(node => node.value).join(', '); // object, null, null, null
```

Members

(static) data :*

The end data model of the route containing the result.

Type:
  • *
Properties:
Name Type Description
data
Source:

(static) index :string

The end key name of the route indexing the result.

Type:
  • string
Properties:
Name Type Description
index
Source:

(static) last :Route

The last node in the route.

Type:
  • Route
Properties:
Name Type Description
last
Source:

(static) name :string

The name of this node.

Type:
  • string
Properties:
Name Type Description
name
Source:

(static) next :Route

The next sibling of this node.

Type:
  • Route
Properties:
Name Type Description
next
Source:

(static) parent :Route

The previous sibling of this node.

Type:
  • Route
Properties:
Name Type Description
parent
Source:

(static) path :Array.<string>

The key path of the route.

Type:
  • Array.<string>
Properties:
Name Type Description
path
Source:

(static) result :*

The result of the route.

Type:
  • *
Properties:
Name Type Description
result
Source:

(static) root :Route

The root node of the route.

Type:
  • Route
Properties:
Name Type Description
root
Source:

(static) value :*

The value of this node.

Type:
  • *
Properties:
Name Type Description
value
Source:

Methods

(static) append(name, value) → {Route}

Adds a node to the end of this Route.

Parameters:
Name Type Description
name string

The name of the new node.

value *

The value of the new node.

Source:
Returns:
Type
Route

(static) assign(value) → {Route}

Creates an updated Route, creating objects as necessary, and updating the Routes result to the value.

Parameters:
Name Type Description
value *

The value to assign to the route's result.

Source:
Returns:
Type
Route

(static) assign(value) → {Route}

Creates an updated Route, creating objects as necessary, and updating the Routes result to the value.

Parameters:
Name Type Description
value *

The value to assign to the route's result.

Source:
Returns:
Type
Route

(static) clone() → {Route}

Creates a duplicate of this Route

Source:
Returns:
Type
Route

(static) find(data, name) → {string}

Performs a case-insensitive search for a matching key in the data object or defaults to the name.

Parameters:
Name Type Description
data *

The data object to search in.

name string

The name of the key to find.

Source:
Returns:
Type
string

(static) select(path) → {Route}

Clones the Route appended with the data selection.

Parameters:
Name Type Description
path Array.<string>

An array of member names defining the data selection path.

Source:
Returns:
Type
Route

(static) select(source, path) → {Route}

Clones the Route appended with the data selection.

Parameters:
Name Type Description
source *

The root Route or data model to select from.

path Array.<string>

An array of member names defining the data selection path.

Source:
Returns:
Type
Route