Skip to content

Commit 0df68b0

Browse files
committed
update readme
1 parent 3c7ffb8 commit 0df68b0

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,28 @@
22

33
# lars::Event
44

5-
A thread-safe C++11 event-listener template.
5+
A thread-safe C++11 event-listener template and observable value implementation.
66

77
# Example
88

9+
## lars::Event
910

11+
```c++
12+
lars::Event<float,float> onClick;
13+
auto observer = onClick.createObserver([](auto x, auto y){ handleClick(x,y); });
14+
onClick.emit(0,0); // emits event to all observers
15+
observer.reset(); // removes observer from event
16+
```
17+
18+
## lars::ObservableValue
19+
20+
```c++
21+
ObservableValue a = 1;
22+
ObservableValue b = 2;
23+
DependentObservableValue sum([](auto a, auto b){ return a+b; },a,b);
24+
DependentObservableValue resultString([](auto v){ return "The result is " + std::to_string(v); }, sum);
25+
resultString.onChange.connect([](auto &r){ std::cout << r << std::endl; });
26+
```
1027

1128
# Installation and usage
1229

0 commit comments

Comments
 (0)