33C++React is reactive programming library for C++11.
44
55Generally speaking, it provides abstractions to handle change propagation and data processing for a push-based event model.
6- A more practical description is that it enables coordinated, multi-layered - and potentially parallel - execution of callbacks.
6+ A more practical description is that it enables coordinated, multi-layered - _ and potentially parallel _ - execution of callbacks.
77All this happens implicitly, based on declarative definitions, with guarantees regarding
88
99- _ update minimality_ - nothing is re-calculated or processed unnecessarily;
1010- _ glitch freedom_ - no transiently inconsistent data sets;
11- - _ thread safety_ - no data races for parallel execution.
11+ - _ thread safety_ - no data races for parallel execution by avoiding side effects .
1212
1313The core abstractions of the library are
1414
@@ -30,19 +30,17 @@ Additional features include
3030[ If you're interested in learning about C++React, have a look at its documentation.] ( http://schlangster.github.io/cpp.react/ )
3131
3232
33- ## Development
33+ ## Using the library
3434
35- This library is a work-in-progress and should not be considered release quality yet.
35+ This library is a work-in-progress. It should not be considered release quality yet and its API might still change .
3636It is, however, in a perfectly usable state and has already received a fair amount of testing and tuning.
3737
38-
3938### Dependencies
4039
4140* [ Intel TBB 4.2] ( https://www.threadingbuildingblocks.org/ ) (required)
4241* [ Google test framework] ( https://code.google.com/p/googletest/ ) (optional, to compile the unit tests)
4342* [ Boost 1.55.0 C++ Libraries] ( http://www.boost.org/ ) (optional, to include Reactor.h, which requires ` boost::coroutine ` )
4443
45-
4644### Compiling
4745
4846C++React has been tested with the following compilers:
@@ -69,20 +67,21 @@ For more details, refer to the [Build instructions](https://github.com/schlangst
6967### Signals
7068
7169Signals are self-updating reactive variables.
72- They can be combined as expressions to create new signals, which are automatically re-calculated whenever one of their dependencies changes .
70+ They can be combined in expressions to create new signals, which are automatically re-calculated when their dependencies change .
7371
7472``` C++
7573using namespace std ;
7674using namespace react ;
7775
78- // Define a reactive domain that uses single-threaded, sequential updating
76+ // Defines a reactive domain that uses single-threaded, sequential updating
7977REACTIVE_DOMAIN (D, sequential)
8078
81- // Define aliases for types of the given domain,
79+ // Defines aliases for types of the given domain,
8280// e.g. using VarSignalT<X> = VarSignal<D,X>
8381USING_REACTIVE_DOMAIN (D)
8482
8583// Two reactive variables that can be manipulated imperatively
84+ // to input external changes
8685VarSignalT<int > width = MakeVar<D>(1 );
8786VarSignalT<int > height = MakeVar<D>(2 );
8887
@@ -110,15 +109,16 @@ Observe(area, [] (int newValue) {
110109});
111110```
112111
113- Overloaded operators for signal types allow to omit `MakeSignal` in this case for a more concise syntax:
112+ Overloaded operators for signal types allow to omit `MakeSignal` for a more concise syntax:
114113```C++
115114// Lift as reactive expression - equivalent to previous example
116115SignalT<int> area = width * height;
117116```
118117
119118### Event streams
120119
121- Event streams represent flows of discrete values. They are first-class objects and can be merged, filtered, transformed or composed to more complex types:
120+ Unlike signals, event streams are not centered on changing state, but represent flows of discrete values.
121+ They are first-class objects and can be merged, filtered, transformed or composed to more complex types:
122122
123123``` C++
124124using namespace std ;
@@ -128,39 +128,27 @@ REACTIVE_DOMAIN(D, sequential)
128128USING_REACTIVE_DOMAIN (D)
129129
130130// Two event sources
131- EventSourceT<Token> leftClicked = MakeEventSource<D>();
132- EventSourceT<Token> rightClicked = MakeEventSource<D>();
131+ EventSourceT<Token> leftClick = MakeEventSource<D>();
132+ EventSourceT<Token> rightClick = MakeEventSource<D>();
133133
134134// Merge both event streams
135- EventsT<Token> merged = leftClicked | rightClicked ;
135+ EventsT<Token> anyClick = leftClick | rightClick ;
136136
137137// React to events
138- Observe (merged , [ ] (Token) {
138+ Observe (anyClick , [ ] (Token) {
139139 cout << "clicked!" << endl;
140140});
141141```
142142```
143- rightClicked.Emit(); // => clicked!
143+ leftClick.Emit(); // => clicked!
144+ rightClick.Emit(); // => clicked!
144145```
145146
146147### Parallelism and concurrency
147148
148- The change propagation is handled implicitly.
149- Depending on the selected concurrency policy, updates can be parallelized:
150-
151- ```C++
152- // Sequential updating
153- REACTIVE_DOMAIN(D, sequential)
154-
155- VarSignalT<int> a = MakeVar<D>(1);
156- VarSignalT<int> b = MakeVar<D>(2);
157- VarSignalT<int> c = MakeVar<D>(3);
158-
159- SignalT<int> x = (a + b) * c;
160- ```
149+ When enabling it through the concurrency policy, updates are automatically parallelized:
161150
162151```C++
163- // Parallel updating
164152REACTIVE_DOMAIN(D, parallel)
165153
166154VarSignalT<int> in = MakeVar<D>(0);
@@ -181,11 +169,6 @@ SignalT<int> op2 = MakeSignal(in, [] (int in)
181169SignalT<int> out = op1 + op2;
182170```
183171
184- ### More examples
185-
186- * [ Examples] ( https://github.com/schlangster/cpp.react/tree/master/examples/src )
187- * [ Test cases] ( https://github.com/schlangster/cpp.react/tree/master/tests/src )
188-
189172## Acknowledgements
190173
191174The API of C++React has been inspired by the following two research papers:
0 commit comments