FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpp.react/examples/src/BasicObservers.cpp at master · TheKK/cpp.react · GitHub
TheKK
/
cpp.react
Public
forked from
snakster/cpp.react
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
cpp.react
/
examples
/
src
/
BasicObservers.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
53 lines (39 loc) · 1.33 KB
Breadcrumbs
cpp.react
/
examples
/
src
/
BasicObservers.cpp
Copy path
File metadata and controls
53 lines (39 loc) · 1.33 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//
Copyright Sebastian Jeckel 2017.
//
Distributed under the Boost Software License, Version 1.0.
//
(See accompanying file LICENSE_1_0.txt or copy at
//
http://www.boost.org/LICENSE_1_0.txt)
#
include
<
iostream
>
#
include
<
string
>
#
include
<
utility
>
#
include
"
react/state.h
"
#
include
"
react/event.h
"
#
include
"
react/observer.h
"
//
/////////////////////////////////////////////////////////////////////////////////////////////////
//
/ Example 1 - Creating subject-bound observers
//
/////////////////////////////////////////////////////////////////////////////////////////////////
namespace
example1
{
using
namespace
std
;
using
namespace
react
;
Group group;
StateVar<
int
> x = StateVar<
int
>::Create(group,
1
);
void
Run
()
{
cout <<
"
Example 1 - Creating observers
"
<< endl;
{
auto
st = State<
int
>::
Create
([] (
int
x) {
return
x; }, x);
auto
obs =
Observer::Create
([] (
int
v) { cout << v << endl; }, st);
x.
Set
(
2
);
//
output: 2
}
x.
Set
(
3
);
//
no ouput
cout << endl;
}
}
//
/////////////////////////////////////////////////////////////////////////////////////////////////
//
/ Run examples
//
/////////////////////////////////////////////////////////////////////////////////////////////////
int
main
()
{
example1::Run
();
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL