[dispatcher] add dispatcher macro

This commit is contained in:
2019-04-21 15:29:43 +03:00
parent 7c879ee159
commit 1d4fd3b2a9
4 changed files with 142 additions and 3 deletions

View File

@@ -1,5 +1,6 @@
package demo;
import demo.dispatch.DemoDispatcher;
import haxework.net.JsonLoader;
import demo.popup.ColorPopup;
import haxework.App;
@@ -30,16 +31,28 @@ import haxework.log.TraceLogger;
}
}
class Demo extends App {
class Demo extends App implements DemoListener {
public static function main() {
L.push(new TraceLogger());
var app = new App();
var app = new Demo();
app.resources.image.put("logo", HaxeLogo.resolve());
Theme.setColor(0x33aa33);
app.start(new DemoView());
var dispatcher = new DemoDispatcher();
dispatcher.connect(app);
dispatcher.test1Change.emit();
dispatcher.test2Change.emit(1);
dispatcher.test3Change.emit(1, "test");
dispatcher.test4Change.emit(app);
dispatcher.disconnect(app);
dispatcher.test1Change.emit();
dispatcher.test2Change.emit(1);
dispatcher.test3Change.emit(1, "test");
dispatcher.test4Change.emit(app);
new JsonLoader().GET("http://umix.tv/channel/data2/renova.json")
.then(function(data:Array<Model>) {
app.resources.any.put("data", data);
@@ -47,4 +60,21 @@ class Demo extends App {
})
.catchError(function(error) trace(error));
}
public function test1():Void {
trace('test1');
}
public function test2(a:Int):Void {
trace('test2', a);
}
public function test3(a:Int, b:String):Void {
trace('test3', a, b);
}
public function test4(app: App):Void {
trace('test4', app);
}
}

View File

@@ -0,0 +1,14 @@
package demo.dispatch;
import haxework.App;
interface DemoListener {
public function test1():Void;
public function test2(a:Int):Void;
public function test3(a:Int, b:String):Void;
public function test4(app:App):Void;
}
@:dispatcher(DemoListener) class DemoDispatcher {
public function new() {}
}