-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from TheLartians/refactor
refactor event and observable value
- Loading branch information
Showing
11 changed files
with
410 additions
and
406 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,44 @@ | ||
[![Build Status](https://travis-ci.com/TheLartians/Event.svg?branch=master)](https://travis-ci.com/TheLartians/Event) | ||
|
||
# lars::event | ||
# lars::Event | ||
|
||
A c++11 event-listener system template. See [Examples](https://github.com/TheLartians/Event/tree/master/examples) for usage. | ||
A thread-safe event-listener template and observable value implementation for C++17. | ||
|
||
# Examples | ||
|
||
Full examples can be found in the [examples directory](https://github.com/TheLartians/Event/tree/master/examples). | ||
|
||
## lars::Event | ||
|
||
```c++ | ||
lars::Event<float,float> onClick; | ||
auto observer = onClick.createObserver([](auto x, auto y){ handleClick(x,y); }); | ||
onClick.emit(0,0); // emits event to all observers | ||
observer.reset(); // removes observer from event | ||
``` | ||
## lars::ObservableValue | ||
```c++ | ||
lars::ObservableValue a = 1; | ||
lars::ObservableValue b = 2; | ||
lars::DependentObservableValue sum([](auto a, auto b){ return a+b; },a,b); | ||
sum.onChange.connect([](auto &v){ std::cout << "The result is " << r << std::endl; }); | ||
a.set(3); // -> "The result is 5" | ||
``` | ||
|
||
# Installation and usage | ||
|
||
With [CPM](https://github.com/TheLartians/CPM), lars::Event can be added to your project by adding the following to your projects' `CMakeLists.txt`. | ||
|
||
```cmake | ||
CPMAddPackage( | ||
NAME LarsEvent | ||
VERSION 2.0 | ||
GIT_REPOSITORY https://github.com/TheLartians/Event.git | ||
) | ||
target_link_libraries(myProject LarsEvent) | ||
``` | ||
|
||
Alternatively, download the repository include it via `add_subdirectory`. Installing lars::Event will make it findable in CMake's `find_package`. |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.