Repository navigation
Graph model
Reactive programming is declarative by nature. You don't set reactive values manually, but declare how to calculate them in terms of a function. A runtime engine takes care of running that function whenever necessary. This principle applies to signals, event streams or any other abstraction provided by this library.
The dependency relations between reactive values implicitly form a graph which models the dataflow.
Each reactive value is a node and edges denote a dependency relation.
If an edge exists from a to b that means a will propagate its changes to b.
In other words, after a node changed, all its successors will be updated.
To give an example, let a, b and c be arbitrary reactive signals. x is another signal that combines the former through use of primitive operators:
SignalT<int> a = ...;
SignalT<int> b = ...;
SignalT<int> c = ...;
SignalT<int> x = (a + b) * c;This is the respective dataflow graph:

The graph data structures are not directly exposed by the API; they are accessible through lightweight proxies instead. Such a proxy is essentially a shared pointer to the heap-allocated node. The concrete type of the node is hidden behind the proxy.
One observation made from the previous example is that not all nodes in the graph are bound to a proxy; the temporary sub-expression a + b results in a node as well.
If a new node is created, it takes shared ownership of its dependencies, because it needs them to calculate its own value. This prevents the a + b node from disappearing.
The resulting reference graph is similar to the dataflow graph, but with reverse edges (and as such, a DAG as well):

The number inside each node denotes its reference count. On the left are the proxy instances exposed by the API.
Assuming the handles for a, b and c would go out of scope but x remains, the reference count of all nodes is still 1, until x disappears as well.
Once that happens, the graph is deconstructed from the bottom up.
As stated before, a reactive graph is not constructed explicitly, but rather a result of declaring reactives and their dependencies.
It is generally not possible to construct cyclic graphs. Attempting to do so as shown in the following example will result in an error:
SignalT<U> a;
SignalT<U> b;
a = MakeSignal(b, ...);
b = MakeSignal(a, ...);b is still invalid at the time of construction, because it's not linked to any node. As such, the code will compile, but fail a runtime assertion.
The exception to this rule are higher order reactives:
VarSignalT<U> in = MakeVar<D>(...);
VarSignalT<SignalT<U>> outer = MakeVar<D>(a);
SignalT<U> flat = Flatten(outer);
// Cycle'd
outer <<= flat;Creating cyclic graphs results in undefined behaviour.