An open API service indexing awesome lists of open source software.

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

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();
```