Skip to content

Commit 0eea52c

Browse files
committed
Added another example.
1 parent 860aada commit 0eea52c

1 file changed

Lines changed: 44 additions & 8 deletions

File tree

examples/src/BasicSignals.cpp

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ namespace example1
4444
VarSignalT<string> firstWord = MakeVar<D>(string("Change"));
4545
VarSignalT<string> secondWord = MakeVar<D>(string("me!"));
4646

47-
SignalT<string> bothWords = MakeSignal(With(firstWord,secondWord), &concatFunc);
47+
SignalT<string> bothWords = MakeSignal(With(firstWord,secondWord), concatFunc);
4848

4949
void Run()
5050
{
@@ -164,7 +164,7 @@ namespace example3
164164
}
165165

166166
///////////////////////////////////////////////////////////////////////////////////////////////////
167-
/// Example 4 - Complex signals
167+
/// Example 4 - Modifying signal values in place
168168
///////////////////////////////////////////////////////////////////////////////////////////////////
169169
namespace example4
170170
{
@@ -174,6 +174,40 @@ namespace example4
174174
REACTIVE_DOMAIN(D)
175175
USING_REACTIVE_DOMAIN(D)
176176

177+
VarSignalT<vector<string>> data = MakeVar<D>(vector<string>{ });
178+
179+
void Run()
180+
{
181+
cout << "Example 4 - Modifying signal values in place" << endl;
182+
183+
data.Modify([] (vector<string>& data) {
184+
data.push_back("Hello");
185+
});
186+
187+
data.Modify([] (vector<string>& data) {
188+
data.push_back("World");
189+
});
190+
191+
for (const auto& s : data.Value())
192+
cout << s << " ";
193+
cout << endl;
194+
// output: Hell World
195+
196+
cout << endl;
197+
}
198+
}
199+
200+
///////////////////////////////////////////////////////////////////////////////////////////////////
201+
/// Example 5 - Complex signals
202+
///////////////////////////////////////////////////////////////////////////////////////////////////
203+
namespace example5
204+
{
205+
using namespace std;
206+
using namespace react;
207+
208+
REACTIVE_DOMAIN(D)
209+
USING_REACTIVE_DOMAIN(D)
210+
177211
// Helpers
178212
using ExprPairT = pair<string,int>;
179213
using ExprVectT = vector<ExprPairT>;
@@ -233,7 +267,7 @@ namespace example4
233267

234268
void Run()
235269
{
236-
cout << "Example 4 - Complex signals (v1)" << endl;
270+
cout << "Example 5 - Complex signals (v1)" << endl;
237271

238272
Observe(expressions, printExpressions);
239273

@@ -282,7 +316,7 @@ namespace example4
282316

283317
void Run()
284318
{
285-
cout << "Example 4 - Complex signals (v2)" << endl;
319+
cout << "Example 5 - Complex signals (v2)" << endl;
286320

287321
Observe(expressions, printExpressions);
288322

@@ -324,7 +358,7 @@ namespace example4
324358

325359
void Run()
326360
{
327-
cout << "Example 4 - Complex signals (v3)" << endl;
361+
cout << "Example 5 - Complex signals (v3)" << endl;
328362

329363
Observe(expressions, printExpressions);
330364

@@ -348,9 +382,11 @@ int main()
348382

349383
example3::Run();
350384

351-
example4::v1::Run();
352-
example4::v2::Run();
353-
example4::v3::Run();
385+
example4::Run();
386+
387+
example5::v1::Run();
388+
example5::v2::Run();
389+
example5::v3::Run();
354390

355391
return 0;
356392
}

0 commit comments

Comments
 (0)