Last active
December 23, 2015 09:19
-
-
Save back2dos/6613772 to your computer and use it in GitHub Desktop.
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
#if macro | |
import haxe.macro.Context; | |
import haxe.macro.Expr; | |
#end | |
abstract Signal<T>(Array<T>) | |
{ | |
public inline function new() | |
{ | |
this = []; | |
} | |
public inline function add(listener:T):Void | |
{ | |
this.push(listener); | |
} | |
private inline function asArray():Array<T> return this; | |
public function remove(listener:T):Void | |
{ | |
var i = 0; | |
while (i < this.length) | |
{ | |
if (Reflect.compareMethods(this[i], listener)) | |
this.splice(i, 1); | |
else | |
i++; | |
} | |
} | |
static public macro function dispatch(ethis:Expr, args:Array<Expr>):Expr | |
{ | |
return macro | |
for (__handler in @:privateAccess $ethis.asArray()) | |
__handler($a{args}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment