Created
April 2, 2014 06:47
-
-
Save AxGord/9929065 to your computer and use it in GitHub Desktop.
Ultra fast and small strict typed simple signals.
This file contains hidden or 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
package ; | |
class FastSignalsExample { | |
static function main() { | |
var o = new Signal1<String>(); | |
o.add(function(v) trace(v)); | |
o.dispatch('Hello'); | |
} | |
} | |
class Signal0 extends SCore<Void->Void> { | |
inline public function dispatch():Void for (e in list) e(); | |
} | |
class Signal1<T> extends SCore<T->Void> { | |
inline public function dispatch(v:T):Void for (e in list) e(v); | |
} | |
class Signal2<A,B> extends SCore<A->B->Void> { | |
inline public function dispatch(a:A, b:B):Void for (e in list) e(a, b); | |
} | |
class Signal3<A,B,C> extends SCore<A->B->C->Void> { | |
inline public function dispatch(a:A, b:B, c:C):Void for (e in list) e(a, b, c); | |
} | |
class SCore<T> { | |
private var list:List<T>; | |
inline public function new() list = new List(); | |
inline public function add(f:T):Void list.add(f); | |
inline public function remove(f:T):Void list.remove(f); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment