https://github.com/webfreak001/eventsystem
Tiny event system in D using delegates
https://github.com/webfreak001/eventsystem
Last synced: 5 months ago
JSON representation
Tiny event system in D using delegates
- Host: GitHub
- URL: https://github.com/webfreak001/eventsystem
- Owner: WebFreak001
- License: unlicense
- Created: 2015-10-12T21:00:51.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2021-06-10T16:37:53.000Z (about 5 years ago)
- Last Synced: 2025-02-28T14:48:10.926Z (over 1 year ago)
- Language: D
- Size: 5.86 KB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Tiny Event System
Its just 35 lines of code + unittests and it supports regular events & cancelable events!
Usage:
```d
import tinyevent;
// Regular event
Event!string onStringChange;
static assert(isEvent!onStringChange);
static assert(isEmittable!onStringChange);
onStringChange ~= (str) { /* Handle new string */ };
onStringChange.emit("Foo");
```
```d
import tinyevent;
// Cancelable
Cancelable!bool onQuit;
static assert(isCancelable!onQuit);
static assert(isEmittable!onQuit);
onQuit ~= (force) { return force || !saved; }
// When pressing X:
if(!onQuit.emit(false))
showUnsavedChangesDialog();
else
exit();
```