NativeScript Routed Values
A NativeScript module for implementing routed value graphs.
NativeScript Toolbox
This module is part of nativescript-toolbox.
License
Platforms
- Android
- iOS
Installation
Run
tns plugin add nativescript-routed-values
inside your app project to install the module.
What are "routed values"?
The idea is that you can build graphs of values.
You define one or more root element that can have one or more child that also can handle one or more child and so on.
For example:
A1
/ \
B1 B2
/ \ / \
C1 C2 C3 C4
Here you have the root element A1
that has the children B1
and B2
.
B1
itself has the children C1
and C2
.
B2
is the parent of C3
and C4
.
The code of that graph looks like this:
; // the root element; // the children of A1;;A1.addChildrenB1, B2; // the children of B1;;B1.addChildrenC1, C2; // the children of B2;;B2.addChildrenC3, C4;
Now if you change the value of A1
it will notify that value to all its children.
And these children will notify value changes to their children and so on.
By default the highest values wins.
You can set the value by using the innerValue
property:
A1.innerValue = 5979;
The effect is that A1
will raise a change event for the value
property of itself and their children B1
and B2
.
B1
and B2
will also raise change events for their children.
Other direction
You also can use the "other" direction, what means that the lower value "wins".
In that case you have to set Descending
value of the RouterStradegy
enum
in the constructor of a routed value.
; ;
Example
Data binding
The graph above is realized as demo app.

The values of the left side are the routed values provided by value
property.
The values of the right side are the "real" / inner values provided by innerValue
property.
To increase a value simply tap on it.
Events
onValueChanged
; ;A1.name = 'A1';A1.onValueChanged; A1.innerValue = 5979;
Classes
TrafficLight
This represents a "traffic light" and uses the following enum:
RoutedValue<T>
This is the generic version of a routed value and can be used for all comparable value types, especially for enums:
; ;v.innerValue = MyEnum.Value1;