-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
124 additions
and
109 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
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
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
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
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
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,46 +1,52 @@ | ||
# Defining Events In Your Classes | ||
libnick events are designed to easily integrate within your classes to easily notify consumers of changes in state of an object. | ||
|
||
Let's take a look at `ConfigurationBase` and how it defines and uses events. | ||
Let's take a look at `Nickvision::App::DataFileBase` and how it defines and uses events. | ||
|
||
```cpp | ||
class ConfigurationBase | ||
namespace Nickvision::App | ||
{ | ||
public: | ||
... | ||
Events::Event<Events::EventArgs>& saved() | ||
{ | ||
return m_saved; | ||
} | ||
|
||
bool save() | ||
{ | ||
... | ||
saved({}); //Same as saved.invoke({}); | ||
... | ||
} | ||
|
||
private: | ||
... | ||
Events::Event<Events::EventArgs> m_saved; | ||
}; | ||
class DataFileBase | ||
{ | ||
public: | ||
... | ||
Events::Event<Events::EventArgs>& saved() | ||
{ | ||
return m_saved; | ||
} | ||
|
||
bool save() | ||
{ | ||
... | ||
saved({}); //Same as saved.invoke({}); | ||
... | ||
} | ||
|
||
private: | ||
... | ||
Events::Event<Events::EventArgs> m_saved; | ||
}; | ||
} | ||
``` | ||
Here we can see how `ConfigurationBase` defines a `saved` event, exposes it to the consumer, and triggers/invokes the event within its `save` method. | ||
Here we can see how `Nickvision::App::DataFileBase` defines a `saved` event, exposes it to the consumer, and triggers/invokes the event within its `save` method. | ||
A consumer of `ConfigurationBase` can easily subscribe to the event and have its handler called when the configuration object is saved: | ||
A consumer of `Nickvision::App::DataFileBase` can easily subscribe to the event and have its handler called when the configuration object is saved: | ||
```cpp | ||
void handler(const Nickvision::Events::EventArgs& e) | ||
using namespace Nickvision::App; | ||
using namespace Nickvision::Events; | ||
void handler(const EventArgs& e) | ||
{ | ||
std::cout << "Config saved." << std::endl; | ||
} | ||
int main() | ||
{ | ||
ConfigurationBase base{ ... }; | ||
DataFileBase base{ ... }; | ||
base.saved() += handler; | ||
base.save(); | ||
} | ||
``` | ||
|
||
This program will print "Config saved." as a result of the event being invoke once the save method was called. | ||
This program will print `Config saved.` as a result of the event being invoke once the save method was called. |
Oops, something went wrong.