bindTo fixes
This commit is contained in:
+1
-1
@@ -65,7 +65,7 @@ class Bind {
|
|||||||
public static function checkField(field:Expr):{e:Expr, field:ClassField} {
|
public static function checkField(field:Expr):{e:Expr, field:ClassField} {
|
||||||
switch (field.expr) {
|
switch (field.expr) {
|
||||||
case EField(e, field):
|
case EField(e, field):
|
||||||
var classType = Context.typeof(e).getClass();
|
var classType = Context.typeof(e).follow().getClass();
|
||||||
if (classType == null || !isBindable(classType)) {
|
if (classType == null || !isBindable(classType)) {
|
||||||
Context.error('\'${e.toString()}\' must be bindx.IBindable', e.pos);
|
Context.error('\'${e.toString()}\' must be bindx.IBindable', e.pos);
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ class BindMacros {
|
|||||||
Context.warning('$INLINE_SETTER ignored. Setter already exist', inlineSetter.pos);
|
Context.warning('$INLINE_SETTER ignored. Setter already exist', inlineSetter.pos);
|
||||||
var fieldName = field.name;
|
var fieldName = field.name;
|
||||||
var setter = fields.find(function (it) return it.name == 'set_$fieldName');
|
var setter = fields.find(function (it) return it.name == 'set_$fieldName');
|
||||||
if (setter == null) return;
|
if (setter != null) {
|
||||||
switch (setter.kind) {
|
switch (setter.kind) {
|
||||||
case FFun(func):
|
case FFun(func):
|
||||||
patchField = field;
|
patchField = field;
|
||||||
@@ -105,7 +105,7 @@ class BindMacros {
|
|||||||
};
|
};
|
||||||
patchField = null;
|
patchField = null;
|
||||||
case _:
|
case _:
|
||||||
|
}
|
||||||
}
|
}
|
||||||
res.push(field);
|
res.push(field);
|
||||||
|
|
||||||
|
|||||||
@@ -63,8 +63,9 @@ class BindSignalProvider implements IBindingSignalProvider {
|
|||||||
function __unbind__() $expr.$signalName.remove(listener);
|
function __unbind__() $expr.$signalName.remove(listener);
|
||||||
}
|
}
|
||||||
case FVar(_, _):
|
case FVar(_, _):
|
||||||
|
var type = field.type.follow().toComplexType();
|
||||||
macro {
|
macro {
|
||||||
var listener = function (from, to) $target = to;
|
var listener = function (from:$type, to:$type) $target = to;
|
||||||
$expr.$signalName.add(listener);
|
$expr.$signalName.add(listener);
|
||||||
function __unbind__() $expr.$signalName.remove(listener);
|
function __unbind__() $expr.$signalName.remove(listener);
|
||||||
}
|
}
|
||||||
@@ -89,7 +90,7 @@ class BindSignalProvider implements IBindingSignalProvider {
|
|||||||
|
|
||||||
public function getDisposeBindingsExpr(expr:ExprOf<IBindable>, type:Type):Expr {
|
public function getDisposeBindingsExpr(expr:ExprOf<IBindable>, type:Type):Expr {
|
||||||
return macro {
|
return macro {
|
||||||
var meta = haxe.rtti.Meta.getFields($p{type.toString().split(".")});
|
var meta = haxe.rtti.Meta.getFields(std.Type.getClass($expr));
|
||||||
if (meta != null) for (m in std.Reflect.fields(meta)) {
|
if (meta != null) for (m in std.Reflect.fields(meta)) {
|
||||||
var data:Dynamic<String> = std.Reflect.field(meta, m);
|
var data:Dynamic<String> = std.Reflect.field(meta, m);
|
||||||
if (std.Reflect.hasField(data, $v{BIND_SIGNAL_META})) {
|
if (std.Reflect.hasField(data, $v{BIND_SIGNAL_META})) {
|
||||||
@@ -127,7 +128,7 @@ class BindSignalProvider implements IBindingSignalProvider {
|
|||||||
}
|
}
|
||||||
return $i{signalPrivateName};
|
return $i{signalPrivateName};
|
||||||
};
|
};
|
||||||
var getterAccess = [];
|
var getterAccess = [APrivate];
|
||||||
if (inlineSignalGetter.isNotNullAndTrue()) getterAccess.push(AInline);
|
if (inlineSignalGetter.isNotNullAndTrue()) getterAccess.push(AInline);
|
||||||
|
|
||||||
res.push({
|
res.push({
|
||||||
|
|||||||
@@ -31,6 +31,15 @@ class TestProperty extends haxe.unit.TestCase {
|
|||||||
|
|
||||||
assertEquals(callNum, 2);
|
assertEquals(callNum, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test2() {
|
||||||
|
var p = new BindableProperty();
|
||||||
|
var t = {a:""};
|
||||||
|
Bind.bindTo(p.s, t.a);
|
||||||
|
|
||||||
|
p.s = "123";
|
||||||
|
assertEquals(t.a, p.s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class BindableProperty implements bindx.IBindable {
|
class BindableProperty implements bindx.IBindable {
|
||||||
|
|||||||
Reference in New Issue
Block a user