[dispatcher] rename signal vars
This commit is contained in:
@@ -43,15 +43,15 @@ class Demo extends App implements DemoListener {
|
||||
|
||||
var dispatcher = new DemoDispatcher();
|
||||
dispatcher.connect(app);
|
||||
dispatcher.test1Change.emit();
|
||||
dispatcher.test2Change.emit(1);
|
||||
dispatcher.test3Change.emit(1, "test");
|
||||
dispatcher.test4Change.emit(app);
|
||||
dispatcher.test1Signal.emit();
|
||||
dispatcher.test2Signal.emit(1);
|
||||
dispatcher.test3Signal.emit(1, "test");
|
||||
dispatcher.test4Signal.emit(app);
|
||||
dispatcher.disconnect(app);
|
||||
dispatcher.test1Change.emit();
|
||||
dispatcher.test2Change.emit(1);
|
||||
dispatcher.test3Change.emit(1, "test");
|
||||
dispatcher.test4Change.emit(app);
|
||||
dispatcher.test1Signal.emit();
|
||||
dispatcher.test2Signal.emit(1);
|
||||
dispatcher.test3Signal.emit(1, "test");
|
||||
dispatcher.test4Signal.emit(app);
|
||||
|
||||
new JsonLoader().GET("http://umix.tv/channel/data2/renova.json")
|
||||
.then(function(data:Array<Model>) {
|
||||
@@ -61,19 +61,19 @@ class Demo extends App implements DemoListener {
|
||||
.catchError(function(error) trace(error));
|
||||
}
|
||||
|
||||
public function test1():Void {
|
||||
public function onTest1():Void {
|
||||
trace('test1');
|
||||
}
|
||||
|
||||
public function test2(a:Int):Void {
|
||||
public function onTest2(a:Int):Void {
|
||||
trace('test2', a);
|
||||
}
|
||||
|
||||
public function test3(a:Int, b:String):Void {
|
||||
public function onTest3(a:Int, b:String):Void {
|
||||
trace('test3', a, b);
|
||||
}
|
||||
|
||||
public function test4(app: App):Void {
|
||||
public function onTest4(app: App):Void {
|
||||
trace('test4', app);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,12 +3,12 @@ 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;
|
||||
public function onTest1():Void;
|
||||
public function onTest2(a:Int):Void;
|
||||
public function onTest3(a:Int, b:String):Void;
|
||||
public function onTest4(app:App):Void;
|
||||
}
|
||||
|
||||
@:dispatcher(DemoListener) class DemoDispatcher {
|
||||
@:yield @:dispatcher(DemoListener) class DemoDispatcher {
|
||||
public function new() {}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,14 @@ class DispatcherMacro {
|
||||
this.fields = fields;
|
||||
}
|
||||
|
||||
private static inline function signalName(fieldName:String):String {
|
||||
if (fieldName.substr(0, 2) == "on") {
|
||||
return fieldName.substr(2, 1).toLowerCase() + fieldName.substr(3) + "Signal";
|
||||
} else {
|
||||
return fieldName + "Signal";
|
||||
}
|
||||
}
|
||||
|
||||
public function apply():Array<Field> {
|
||||
var result:Array<Field> = fields.slice(0);
|
||||
var typeName = ExprTools.toString(classType.meta.extract(metaName)[0].params[0]);
|
||||
@@ -43,7 +51,7 @@ class DispatcherMacro {
|
||||
params: argsTypes.map(function(t) return TPType(TypeTools.toComplexType(t))),
|
||||
});
|
||||
result.push({
|
||||
name: '${field.name}Change',
|
||||
name: signalName(field.name),
|
||||
access: [APublic],
|
||||
pos: Context.currentPos(),
|
||||
kind: FProp('default', 'null', type, Context.parse('new haxework.signal.Signal.${signal}()', Context.currentPos())),
|
||||
@@ -63,7 +71,7 @@ class DispatcherMacro {
|
||||
}],
|
||||
ret: null,
|
||||
expr: macro $b{fields.map(function(field) {
|
||||
return Context.parse('${field.name}Change.connect(listener.${field.name})', Context.currentPos());
|
||||
return Context.parse('${signalName(field.name)}.connect(listener.${field.name})', Context.currentPos());
|
||||
})},
|
||||
}),
|
||||
});
|
||||
@@ -81,7 +89,7 @@ class DispatcherMacro {
|
||||
}],
|
||||
ret: null,
|
||||
expr: macro $b{fields.map(function(field) {
|
||||
return Context.parse('${field.name}Change.disconnect(listener.${field.name})', Context.currentPos());
|
||||
return Context.parse('${signalName(field.name)}.disconnect(listener.${field.name})', Context.currentPos());
|
||||
})},
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package haxework.parser;
|
||||
|
||||
import haxe.macro.TypeTools;
|
||||
import haxe.macro.Context;
|
||||
import haxe.macro.Expr;
|
||||
import haxe.macro.Type;
|
||||
@@ -10,15 +11,20 @@ import haxework.macro.TemplateMacro;
|
||||
|
||||
class Parser {
|
||||
|
||||
private static var processed:Map<String, Bool> = new Map();
|
||||
|
||||
private static function auto():Void {
|
||||
haxe.macro.Compiler.addGlobalMetadata("", "@:build(haxework.parser.Parser.autoRun())", true, true, false);
|
||||
}
|
||||
|
||||
private static macro function autoRun():Array<Field> {
|
||||
var t:Type = Context.getLocalType();
|
||||
switch (t) {
|
||||
case null: return null;
|
||||
var localType = Context.getLocalType();
|
||||
return switch localType {
|
||||
case Type.TInst(_.get() => ct, _):
|
||||
var localName = TypeTools.toString(localType);
|
||||
if (processed.exists(localName)) {
|
||||
return null;
|
||||
}
|
||||
var modify:Bool = false;
|
||||
var fields:Array<Field> = Context.getBuildFields();
|
||||
var result:Array<Field> = [];
|
||||
@@ -51,8 +57,9 @@ class Parser {
|
||||
var dispatcher = new DispatcherMacro(ct, fields);
|
||||
fields = dispatcher.apply();
|
||||
}
|
||||
return modify ? fields : null;
|
||||
default: return null;
|
||||
processed.set(localName, true);
|
||||
modify ? fields : null;
|
||||
default: null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user