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