[dispatcher] rename signal vars
This commit is contained in:
@@ -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