You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Readme.md
+60-1Lines changed: 60 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,7 @@ Try out rpp on [godbolt.org](https://godbolt.org/z/48fh1hcbn)!
21
21
22
22
## Documentation:
23
23
24
-
Refer to [User Guide](https://victimsnino.github.io/ReactivePlusPlus/v2/docs/html/md_docs_2readme.html)for better understanding of concepts of Reactive Programming and [API Reference of RPP](https://victimsnino.github.io/ReactivePlusPlus/v2/docs/html/group__rpp.html) itself.
24
+
Check [User Guide](https://victimsnino.github.io/ReactivePlusPlus/v2/docs/html/md_docs_2readme.html) and [API Reference of RPP](https://victimsnino.github.io/ReactivePlusPlus/v2/docs/html/group__rpp.html).
25
25
26
26
## Note about V2:
27
27
Currently I'm working on RPP v2 (`v2` branch). RPP v2 follows [**"zero-overhead principle"**](https://en.cppreference.com/w/cpp/language/Zero-overhead_principle) and most of the operators are (and will) minimize overhead.
There we are creating observable which emits value via invoking of `getchar` function, then `repeat`s it infinite amount of time till termination event happes. It emits values while symbol is not equal to `0`, takes only not digits, maps them to upper case and then just prints to console.
63
63
64
+
## Why do you need it?
65
+
66
+
Check the [User Guide](https://victimsnino.github.io/ReactivePlusPlus/v2/docs/html/md_docs_2readme.html) for a detailed overview of the Reactive Programming concept and RPP itself.
67
+
68
+
In short, RPP can help you build complex pipelines to distribute values over time, connect "some sources of data" without directly connecting them.
69
+
70
+
Take a look at the example code for using RPP with QT. Here, you can see how to connect a button to a label and update it based on the number of clicks.
QObject::connect(button, &QPushButton::clicked, [&clicks_duration_label, now = std::chrono::high_resolution_clock::now()]() mutable {
89
+
const auto old = std::exchange(now, std::chrono::high_resolution_clock::now());
90
+
clicks_duration_label->setText(QString{"MS since last click %1!"}.arg(std::chrono::duration_cast<std::chrono::milliseconds>(now-old).count()));
91
+
});
92
+
```
93
+
Again directly connected... and it becomes a bit complex.. what if i want to accumulate two buttons at the same time? should i make a separate variable for this case? Build complex state to track it? Ideally it would be nice also to update "MS since last click %1!" at runtime each 1ms... So, looks like each label have to depend on multiple sources of data. It is not a trivial case. In this case it is nice opportunity to try RPP!
94
+
```cpp
95
+
auto button_1 = new QPushButton("Click me!");
96
+
auto button_2 = new QPushButton("Click me!");
97
+
auto clicks_count_label = new QLabel();
98
+
auto clicks_duration_label = new QLabel();
99
+
100
+
const auto clicks_1 = rppqt::source::from_signal(*button_1, &QPushButton::clicked);
101
+
const auto clicks_2 = rppqt::source::from_signal(*button_2, &QPushButton::clicked);
102
+
const auto merged_clicks = clicks_1 | rpp::operators::merge_with(clicks_2);
clicks_duration_label->setText(QString{"MS since last click %1!"}.arg(std::chrono::duration_cast<std::chrono::milliseconds>(ms).count()));
118
+
});
119
+
```
120
+
Now we have separate observables for separate sources of dynamic data like clicks itself, clicks count and time of clicks. As a result, we can combine them in any way we want. At the same time now observables and actions for events can be separated easily - we have "some observable of some clicks or any counted event" and "some observable of durations". How this observables was obtained - doesn't matter. Also we easily built a much more complex pipeline without any difficulties.
0 commit comments