Fixed inheritance issue for bindAll and unbindAll
This commit is contained in:
@@ -12,7 +12,9 @@ class SignalTools {
|
||||
* @param bindable - target object
|
||||
*/
|
||||
static public function unbindAll(bindable:bindx.IBindable):Void {
|
||||
var meta = haxe.rtti.Meta.getFields(std.Type.getClass(bindable));
|
||||
var clazz:Class<Dynamic> = std.Type.getClass(bindable);
|
||||
while (clazz != null) {
|
||||
var meta = haxe.rtti.Meta.getFields(clazz);
|
||||
if (meta != null) for (m in std.Reflect.fields(meta)) {
|
||||
var data = std.Reflect.field(meta, m);
|
||||
if (std.Reflect.hasField(data, BIND_SIGNAL_META)) {
|
||||
@@ -25,6 +27,8 @@ class SignalTools {
|
||||
}
|
||||
}
|
||||
}
|
||||
clazz = std.Type.getSuperClass(clazz);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,7 +72,9 @@ class SignalTools {
|
||||
*/
|
||||
static public function getSignals(bindable:bindx.IBindable, force = true):Map<String, bindx.BindSignal.Signal<Function>> {
|
||||
var signals = new Map<String, bindx.BindSignal.Signal<Function>>();
|
||||
var meta = haxe.rtti.Meta.getFields(std.Type.getClass(bindable));
|
||||
var clazz:Class<Dynamic> = std.Type.getClass(bindable);
|
||||
while (clazz != null) {
|
||||
var meta = haxe.rtti.Meta.getFields(clazz);
|
||||
if (meta != null) for (m in std.Reflect.fields(meta)) {
|
||||
var data = std.Reflect.field(meta, m);
|
||||
if (std.Reflect.hasField(data, BIND_SIGNAL_META)) {
|
||||
@@ -82,6 +88,8 @@ class SignalTools {
|
||||
signals.set(name, signal);
|
||||
}
|
||||
}
|
||||
clazz = std.Type.getSuperClass(clazz);
|
||||
}
|
||||
return signals;
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,31 @@ class InheritanceTest extends BuddySuite {
|
||||
bp.i = 2;
|
||||
callNum.should.be(3);
|
||||
});
|
||||
|
||||
it("bindx should support class inheritance for bindAll", function () {
|
||||
b.s = "a";
|
||||
Bind.bindAll(b, function (_, _, _) callNum++, true);
|
||||
b.s = "b";
|
||||
callNum.should.be(1);
|
||||
b.i = 1;
|
||||
callNum.should.be(2);
|
||||
});
|
||||
|
||||
it("bindx should support class inheritance for unbindAll", function () {
|
||||
b.i = 1;
|
||||
b.s = "a";
|
||||
Bind.bind(b.i, function (_, _) callNum++);
|
||||
Bind.bind(b.s, function (_, _) callNum++);
|
||||
|
||||
b.i = 2;
|
||||
b.s = "b";
|
||||
callNum.should.be(2);
|
||||
Bind.unbindAll(b);
|
||||
|
||||
b.i = 3;
|
||||
b.s = "c";
|
||||
callNum.should.be(2);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user