| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ccd5f37 commit 4850a6a
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,12 +3,12 @@ | |||
| 3 | 3 | C++React is reactive programming library for C++11. | |
| 4 | 4 | ||
| 5 | 5 | Generally 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. | ||
| 7 | 7 | All this happens implicitly, based on declarative definitions, with guarantees regarding | |
| 8 | 8 | ||
| 9 | 9 | - _update minimality_ - nothing is re-calculated or processed unnecessarily; | |
| 10 | 10 | - _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. | ||
| 12 | 12 | ||
| 13 | 13 | The core abstractions of the library are | |
| 14 | 14 | ||
@@ -30,19 +30,17 @@ Additional features include | |||
| 30 | 30 | [If you're interested in learning about C++React, have a look at its documentation.](http://schlangster.github.io/cpp.react/) | |
| 31 | 31 | ||
| 32 | 32 | ||
| 33 | - ## Development | ||
| 33 | + ## Using the library | ||
| 34 | 34 | ||
| 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. | ||
| 36 | 36 | It is, however, in a perfectly usable state and has already received a fair amount of testing and tuning. | |
| 37 | 37 | ||
| 38 | - | ||
| 39 | 38 | ### Dependencies | |
| 40 | 39 | ||
| 41 | 40 | * [Intel TBB 4.2](https://www.threadingbuildingblocks.org/) (required) | |
| 42 | 41 | * [Google test framework](https://code.google.com/p/googletest/) (optional, to compile the unit tests) | |
| 43 | 42 | * [Boost 1.55.0 C++ Libraries](http://www.boost.org/) (optional, to include Reactor.h, which requires `boost::coroutine`) | |
| 44 | 43 | ||
| 45 | - | ||
| 46 | 44 | ### Compiling | |
| 47 | 45 | ||
| 48 | 46 | C++React has been tested with the following compilers: | |
@@ -69,20 +67,21 @@ For more details, refer to the [Build instructions](https://github.com/schlangst | |||
| 69 | 67 | ### Signals | |
| 70 | 68 | ||
| 71 | 69 | Signals 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. | ||
| 73 | 71 | ||
| 74 | 72 | ```C++ | |
| 75 | 73 | using namespace std; | |
| 76 | 74 | using namespace react; | |
| 77 | 75 | ||
| 78 | - // Define a reactive domain that uses single-threaded, sequential updating | ||
| 76 | + // Defines a reactive domain that uses single-threaded, sequential updating | ||
| 79 | 77 | REACTIVE_DOMAIN(D, sequential) | |
| 80 | 78 | ||
| 81 | - // Define aliases for types of the given domain, | ||
| 79 | + // Defines aliases for types of the given domain, | ||
| 82 | 80 | // e.g. using VarSignalT<X> = VarSignal<D,X> | |
| 83 | 81 | USING_REACTIVE_DOMAIN(D) | |
| 84 | 82 | ||
| 85 | 83 | // Two reactive variables that can be manipulated imperatively | |
| 84 | + // to input external changes | ||
| 86 | 85 | VarSignalT<int> width = MakeVar<D>(1); | |
| 87 | 86 | VarSignalT<int> height = MakeVar<D>(2); | |
| 88 | 87 | ||
@@ -110,15 +109,16 @@ Observe(area, [] (int newValue) { | |||
| 110 | 109 | }); | |
| 111 | 110 | ``` | |
| 112 | 111 | ||
| 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: | ||
| 114 | 113 | ```C++ | |
| 115 | 114 | // Lift as reactive expression - equivalent to previous example | |
| 116 | 115 | SignalT<int> area = width * height; | |
| 117 | 116 | ``` | |
| 118 | 117 | ||
| 119 | 118 | ### Event streams | |
| 120 | 119 | ||
| 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: | ||
| 122 | 122 | ||
| 123 | 123 | ```C++ | |
| 124 | 124 | using namespace std; | |
@@ -128,39 +128,27 @@ REACTIVE_DOMAIN(D, sequential) | |||
| 128 | 128 | USING_REACTIVE_DOMAIN(D) | |
| 129 | 129 | ||
| 130 | 130 | // 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>(); | ||
| 133 | 133 | ||
| 134 | 134 | // Merge both event streams | |
| 135 | - EventsT<Token> merged = leftClicked | rightClicked; | ||
| 135 | + EventsT<Token> anyClick = leftClick | rightClick; | ||
| 136 | 136 | ||
| 137 | 137 | // React to events | |
| 138 | - Observe(merged, [] (Token) { | ||
| 138 | + Observe(anyClick, [] (Token) { | ||
| 139 | 139 | cout << "clicked!" << endl; | |
| 140 | 140 | }); | |
| 141 | 141 | ``` | |
| 142 | 142 | ``` | |
| 143 | - rightClicked.Emit(); // => clicked! | ||
| 143 | + leftClick.Emit(); // => clicked! | ||
| 144 | + rightClick.Emit(); // => clicked! | ||
| 144 | 145 | ``` | |
| 145 | 146 | ||
| 146 | 147 | ### Parallelism and concurrency | |
| 147 | 148 | ||
| 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: | ||
| 161 | 150 | ||
| 162 | 151 | ```C++ | |
| 163 | - // Parallel updating | ||
| 164 | 152 | REACTIVE_DOMAIN(D, parallel) | |
| 165 | 153 | ||
| 166 | 154 | VarSignalT<int> in = MakeVar<D>(0); | |
@@ -181,11 +169,6 @@ SignalT<int> op2 = MakeSignal(in, [] (int in) | |||
| 181 | 169 | SignalT<int> out = op1 + op2; | |
| 182 | 170 | ``` | |
| 183 | 171 | ||
| 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 | - | ||
| 189 | 172 | ## Acknowledgements | |
| 190 | 173 | ||
| 191 | 174 | The API of C++React has been inspired by the following two research papers: | |
| Back | FazBrowse Home | New Git URL |
0 commit comments