Skip to content

Commit 5588d31

Browse files
committed
#30 Dataflow model guide is ported from cpp.react (WIP)
1 parent 748cfb7 commit 5588d31

File tree

4 files changed

+992
-0
lines changed

4 files changed

+992
-0
lines changed

doc/dataflow_model.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Dataflow model
2+
3+
Disclaimer: based on [Dataflow model guide from cpp.react](http://snakster.github.io/cpp.react/guides/Dataflow-model.html)
4+
5+
* [Graph model](#graph-model)
6+
* [Input and output nodes](#input-and-output-nodes)
7+
* [Static and dynamic nodes](#static-and-dynamic-nodes)
8+
* [Domains](#domains)
9+
* [Cycles](#cycles)
10+
* [Propagation model](#propagation-model)
11+
* [Transactions](#transactions)
12+
* [Properties](#properties)
13+
* [Conclusions](#conclusions)
14+
15+
## Graph model
16+
17+
The dataflow between reactive values can be modeled (and visualized) as a [directed acyclic graph (DAG)](https://en.wikipedia.org/wiki/Directed_acyclic_graph).
18+
Such a graph can be constructed from the dependency relations; each entity is a node and directed edges denote data propagation paths.
19+
20+
To give an example, let `a`, `b` and `c` be arbitrary signals.
21+
`x` is another signal that is calculated based on the former.
22+
Instead of invoking `make_signal` explicitly, the overloaded `+` operator is used to achieve the same result.
23+
24+
```cpp
25+
ureact::signal<S> x = (a + b) + c;
26+
```
27+
28+
This is the matching dataflow graph:
29+
30+
<p align="left"><img src="../support/data/signals_1.svg"></p>
31+
32+
From a dataflow perspective, what kind of data is propagated and what exactly happens to it in each node is not relevant.
33+
34+
µReact does not expose the graph data structures directly to the user; instead, they are wrapped by lightweight proxies.
35+
Such a proxy is essentially a shared pointer to the heap-allocated node.
36+
Examples of proxy types are `signal`, `observer`.
37+
The concrete type of the node is hidden behind the proxy.
38+
39+
We show this scheme for the previous example:
40+
41+
```cpp
42+
ureact::signal<S> a = make_var(...);
43+
ureact::signal<S> b = make_var(...);
44+
ureact::signal<S> c = make_var(...);
45+
ureact::signal<S> x = (a + b) + c;
46+
```
47+
48+
The `make_var` function allocates the respective node and links it to the returned proxy.
49+
Not all nodes in the graph are bound to a proxy; the temporary sub-expression `a + b` results in a node as well.
50+
If a new node is created, it takes shared ownership of its dependencies, because it needs them to calculate its own value.
51+
This prevents the `a + b` node from disappearing.
52+
53+
The resulting reference graph is similar to the dataflow graph, but with reverse edges (and as such, a DAG as well):
54+
55+
<p align="left"><img src="../support/data/signals_2.svg"></p>
56+
57+
The number inside each node denotes its reference count. On the left are the proxy instances exposed by the API.
58+
Assuming the proxies 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.
59+
Once that happens, the graph is deconstructed from the bottom up.
60+
61+
62+
### Input and output nodes
63+
64+
### Static and dynamic nodes
65+
66+
### Domains
67+
68+
### Cycles
69+
70+
## Propagation model
71+
72+
### Transactions
73+
74+
### Properties
75+
76+
## Conclusions
77+
78+
---------------
79+
80+
[Home](readme.md#reference)

doc/readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ Usage:
1515
* [Tutorial](tutorial.md) - make sure you have read it before the other parts of the documentation
1616
-->
1717
* [Signals vs callbacks](signals_vs_callbacks.md)
18+
* [Dataflow model](dataflow_model.md)
1819
* [Integration](../tests/integration/) - how to get and link this library
1920
* [Examples](../tests/src/examples)

0 commit comments

Comments
 (0)