Merge pull request #5 from profelis/development

speedup, strict mode, typedefs, generics support
This commit is contained in:
Dima Granetchi
2015-01-25 03:47:18 +02:00
18 changed files with 171 additions and 147 deletions
+5 -5
View File
@@ -7,22 +7,22 @@ import bindx.macro.BindMacros;
class Bind { class Bind {
@:noUsing macro static public function bind(field:Expr, listener:Expr):Expr { @:noUsing macro static public function bind(field:Expr, listener:Expr):Expr {
return BindMacros.internalBind(field, listener, true); return BindMacros.bind(field, listener, true);
} }
@:noUsing macro static public function bindTo(field:Expr, target:Expr):Expr { @:noUsing macro static public function bindTo(field:Expr, target:Expr):Expr {
return BindMacros.internalBindTo(field, target); return BindMacros.bindTo(field, target);
} }
@:noUsing macro static public function unbind(field:Expr, ?listener:Expr):Expr { @:noUsing macro static public function unbind(field:Expr, ?listener:Expr):Expr {
return BindMacros.internalBind(field, listener, false); return BindMacros.bind(field, listener, false);
} }
@:noUsing macro static public function notify(field:Expr, ?oldValue:Expr, ?newValue:Expr):Expr { @:noUsing macro static public function notify(field:Expr, ?oldValue:Expr, ?newValue:Expr):Expr {
return BindMacros.internalNotify(field, oldValue, newValue); return BindMacros.notify(field, oldValue, newValue);
} }
@:noUsing macro static public function unbindAll(object:ExprOf<IBindable>):Expr { @:noUsing macro static public function unbindAll(object:ExprOf<IBindable>):Expr {
return BindMacros.internalUnbindAll(object); return BindMacros.unbindAll(object);
} }
} }
+7 -7
View File
@@ -1,29 +1,29 @@
package bindx; package bindx;
import haxe.macro.Expr; import haxe.macro.Expr;
import haxe.macro.Context;
import bindx.macro.BindExtMacros; import bindx.macro.BindExtMacros;
using haxe.macro.Tools; using haxe.macro.Tools;
using bindx.macro.MacroUtils;
@:access(bindx.macro.BindxExtMacro) @:access(bindx.macro.BindxExtMacro)
class BindExt { class BindExt {
@:noUsing macro static public function expr<T>(expr:ExprOf<T>, listener:ExprOf<Null<T>->Null<T>->Void>):ExprOf<Void->Void> { @:noUsing macro static public function expr<T>(expr:ExprOf<T>, listener:ExprOf<Null<T>->Null<T>->Void>):ExprOf<Void->Void> {
return BindxExtMacro.internalBindExpr(expr, listener); return BindxExtMacro.bindExpr(expr, listener);
} }
@:noUsing macro static public function exprTo<T>(expr:ExprOf<T>, target:ExprOf<T>):ExprOf<Void->Void> { @:noUsing macro static public function exprTo<T>(expr:ExprOf<T>, target:ExprOf<T>):ExprOf<Void->Void> {
var type = Context.typeof(expr).toComplexType(); var type = expr.getComplexType();
return BindxExtMacro.internalBindExpr(expr, macro function (_, to:Null<$type>) $target = to); return BindxExtMacro.bindExpr(expr, macro function (_, to:Null<$type>) $target = to);
} }
@:noUsing macro static public function chain<T>(expr:ExprOf<T>, listener:Expr):ExprOf<Void->Void> { @:noUsing macro static public function chain<T>(expr:ExprOf<T>, listener:Expr):ExprOf<Void->Void> {
return BindxExtMacro.internalBindChain(expr, listener); return BindxExtMacro.bindChain(expr, listener);
} }
@:noUsing macro static public function chainTo<T>(expr:ExprOf<T>, target:ExprOf<T>):ExprOf<Void->Void> { @:noUsing macro static public function chainTo<T>(expr:ExprOf<T>, target:ExprOf<T>):ExprOf<Void->Void> {
var type = Context.typeof(expr).toComplexType(); var type = expr.getComplexType();
return BindxExtMacro.internalBindChain(expr, macro function (_, to:Null<$type>) $target = to); return BindxExtMacro.bindChain(expr, macro function (_, to:Null<$type>) $target = to);
} }
} }
+1 -1
View File
@@ -82,7 +82,7 @@ class SignalTools {
if (meta != null) for (m in std.Reflect.fields(meta)) { if (meta != null) for (m in std.Reflect.fields(meta)) {
var data = std.Reflect.field(meta, m); var data = std.Reflect.field(meta, m);
if (std.Reflect.hasField(data, BIND_SIGNAL_META)) { if (std.Reflect.hasField(data, BIND_SIGNAL_META)) {
var signal:bindx.BindSignal.Signal<Dynamic> = cast Reflect.field(bindable, m); var signal:bindx.BindSignal.Signal<Dynamic> = cast std.Reflect.field(bindable, m);
if (signal != null) { if (signal != null) {
signal.removeAll(); signal.removeAll();
var args:Array<Dynamic> = std.Reflect.field(data, BIND_SIGNAL_META); var args:Array<Dynamic> = std.Reflect.field(data, BIND_SIGNAL_META);
+24 -23
View File
@@ -11,6 +11,7 @@ import bindx.macro.BindMacros;
using Lambda; using Lambda;
using StringTools; using StringTools;
using bindx.macro.MacroUtils;
using haxe.macro.Tools; using haxe.macro.Tools;
private typedef FieldExpr = { private typedef FieldExpr = {
@@ -31,7 +32,7 @@ private typedef Chain = {
@:access(bindx.macro.BindMacros) @:access(bindx.macro.BindMacros)
class BindxExtMacro { class BindxExtMacro {
static inline function internalBindChain(expr:Expr, listener:Expr):Expr { static inline function bindChain(expr:Expr, listener:Expr):Expr {
var zeroListener = listenerName(0, ""); var zeroListener = listenerName(0, "");
var chain = null; var chain = null;
try { chain = warnPrepareChain(expr); } catch (e:GenericError) e.contextError(); try { chain = warnPrepareChain(expr); } catch (e:GenericError) e.contextError();
@@ -42,18 +43,8 @@ class BindxExtMacro {
return res; return res;
} }
static inline function unwrapFormatedString(expr:Expr):Expr { static function bindExpr(expr:Expr, listener:Expr):Expr {
return if (MacroStringTools.isFormatExpr(expr)) { var type = expr.getComplexType();
var f = switch (expr.expr) {
case EConst(CString(s)): s;
case _: null;
}
if (f != null) MacroStringTools.formatString(f, expr.pos) else expr;
} else expr;
}
static function internalBindExpr(expr:Expr, listener:Expr):Expr {
var type = Context.typeof(expr).toComplexType();
var listenerNameExpr = macro listener; var listenerNameExpr = macro listener;
var fieldListenerName = "fieldListener"; var fieldListenerName = "fieldListener";
var fieldListenerNameExpr = macro $i{fieldListenerName}; var fieldListenerNameExpr = macro $i{fieldListenerName};
@@ -96,7 +87,7 @@ class BindxExtMacro {
if (!binded.exists(key)) { if (!binded.exists(key)) {
var ecall = switch (c.expr.expr) { var ecall = switch (c.expr.expr) {
case EField(e, field): case EField(e, field):
var type = Context.typeof(e); var type = e.deepTypeof();
var classRef = type.getClass(); var classRef = type.getClass();
var field = classRef.findField(field); var field = classRef.findField(field);
field.kind.match(FMethod(_)); field.kind.match(FMethod(_));
@@ -246,6 +237,7 @@ class BindxExtMacro {
inline static function listenerName(idx:Int, prefix) return '${prefix}listener$idx'; inline static function listenerName(idx:Int, prefix) return '${prefix}listener$idx';
static function prepareChain(fields:Array<FieldExpr>, expr:Expr, prefix = ""):Chain { static function prepareChain(fields:Array<FieldExpr>, expr:Expr, prefix = ""):Chain {
var bsp = BindableMacros.bindingSignalProvider;
var res:Chain = { init:[], bind:[], unbind:[], expr:null }; var res:Chain = { init:[], bind:[], unbind:[], expr:null };
var prevListenerName = listenerName(0, prefix); var prevListenerName = listenerName(0, prefix);
@@ -259,7 +251,7 @@ class BindxExtMacro {
while (++i < fields.length - 1) { while (++i < fields.length - 1) {
var field = fields[i + 1]; var field = fields[i + 1];
var prev = fields[i]; var prev = fields[i];
var type = Context.typeof(field.e).toComplexType(); var type = field.e.getComplexType();
var listenerName = listenerName(i+1, prefix); var listenerName = listenerName(i+1, prefix);
var listenerNameExpr = macro $i { listenerName }; var listenerNameExpr = macro $i { listenerName };
@@ -283,7 +275,7 @@ class BindxExtMacro {
} }
if (prev.bindable) { if (prev.bindable) {
var unbind = BindableMacros.bindingSignalProvider.getClassFieldUnbindExpr(valueExpr, prev.field, prevListenerNameExpr ); var unbind = bsp.getClassFieldUnbindExpr(valueExpr, prev.field, prevListenerNameExpr );
res.bind.push(macro var $value:Null<$type> = null ); res.bind.push(macro var $value:Null<$type> = null );
res.unbind.push(macro if ($valueExpr != null) { $unbind; $valueExpr = null; } ); res.unbind.push(macro if ($valueExpr != null) { $unbind; $valueExpr = null; } );
@@ -291,7 +283,7 @@ class BindxExtMacro {
fieldListenerBody.push(macro if ($valueExpr != null) $unbind ); fieldListenerBody.push(macro if ($valueExpr != null) $unbind );
fieldListenerBody.push(macro $valueExpr = n ); fieldListenerBody.push(macro $valueExpr = n );
fieldListenerBody.push(macro if (n != null) fieldListenerBody.push(macro if (n != null)
$ { BindableMacros.bindingSignalProvider.getClassFieldBindExpr(macro n, prev.field, prevListenerNameExpr ) }); $ { bsp.getClassFieldBindExpr(macro n, prev.field, prevListenerNameExpr ) });
} }
var callPrevArgs = prev.params != null ? [] : [macro o != null ? o.$fieldName : null, macro n != null ? n.$fieldName : null]; var callPrevArgs = prev.params != null ? [] : [macro o != null ? o.$fieldName : null, macro n != null ? n.$fieldName : null];
var callPrev = macro $prevListenerNameExpr($a { callPrevArgs } ); var callPrev = macro $prevListenerNameExpr($a { callPrevArgs } );
@@ -299,8 +291,7 @@ class BindxExtMacro {
if (field.params != null) { if (field.params != null) {
fieldListenerBody.unshift(macro $i { oldValue } = n); fieldListenerBody.unshift(macro $i { oldValue } = n);
fieldListenerBody.unshift(macro try { n = $e; } catch (e:Dynamic) { }); fieldListenerBody.unshift(macro var n:Null<$type> = try { $e; } catch (_:Dynamic) { null; });
fieldListenerBody.unshift(macro var n:Null < $type > = null);
fieldListenerBody.unshift(macro var o:Null<$type> = $i{oldValue} ); fieldListenerBody.unshift(macro var o:Null<$type> = $i{oldValue} );
res.init.push(macro var $oldValue:Null<$type> = null); res.init.push(macro var $oldValue:Null<$type> = null);
@@ -310,7 +301,7 @@ class BindxExtMacro {
} else { } else {
if (prev.bindable) { if (prev.bindable) {
fieldListenerBody.unshift(macro if (o != null) fieldListenerBody.unshift(macro if (o != null)
${BindableMacros.bindingSignalProvider.getClassFieldUnbindExpr(macro o, prev.field, prevListenerNameExpr )} ${bsp.getClassFieldUnbindExpr(macro o, prev.field, prevListenerNameExpr )}
); );
} }
fieldListener = macro function $listenerName (o:Null<$type>, n:Null<$type>):Void $b { fieldListenerBody }; fieldListener = macro function $listenerName (o:Null<$type>, n:Null<$type>):Void $b { fieldListenerBody };
@@ -322,15 +313,15 @@ class BindxExtMacro {
prevListenerNameExpr = listenerNameExpr; prevListenerNameExpr = listenerNameExpr;
} }
if (zeroListener == null || zeroListener.f.bindable == false) if (zeroListener == null || !zeroListener.f.bindable)
throw new GenericError('${expr.toString()} is not bindable.', expr.pos); throw new GenericError('${expr.toString()} is not bindable.', expr.pos);
var zeroName = zeroListener.f.e.toString(); var zeroName = zeroListener.f.e.toString();
if (zeroName != "this") if (zeroName != "this")
res.init.unshift(macro var $zeroName = $i{zeroName}); res.init.unshift(macro var $zeroName = $i{zeroName});
res.bind.push(BindableMacros.bindingSignalProvider.getClassFieldBindExpr(macro $i{zeroName}, zeroListener.f.field, zeroListener.l )); res.bind.push(bsp.getClassFieldBindExpr(macro $i{zeroName}, zeroListener.f.field, zeroListener.l ));
res.unbind.push(BindableMacros.bindingSignalProvider.getClassFieldUnbindExpr(macro $i{zeroName}, zeroListener.f.field, zeroListener.l )); res.unbind.push(bsp.getClassFieldUnbindExpr(macro $i{zeroName}, zeroListener.f.field, zeroListener.l ));
if (zeroListener.f.params != null) { if (zeroListener.f.params != null) {
res.bind.push(macro ${zeroListener.l}()); res.bind.push(macro ${zeroListener.l}());
@@ -340,5 +331,15 @@ class BindxExtMacro {
} }
return res; return res;
} }
static inline function unwrapFormatedString(expr:Expr):Expr {
return if (MacroStringTools.isFormatExpr(expr)) {
var f = switch (expr.expr) {
case EConst(CString(s)): s;
case _: null;
}
if (f != null) MacroStringTools.formatString(f, expr.pos) else expr;
} else expr;
}
} }
#end #end
+10 -10
View File
@@ -8,30 +8,30 @@ import haxe.macro.Type;
import haxe.macro.Context; import haxe.macro.Context;
using haxe.macro.Tools; using haxe.macro.Tools;
using bindx.macro.MetaUtils; using bindx.macro.MacroUtils;
using Lambda;
@:access(bindx.macro.BindableMacros) @:access(bindx.macro.BindableMacros)
class BindMacros { class BindMacros {
static inline function internalBind(field:Expr, listener:Expr, doBind:Bool):Expr { static inline function bind(field:Expr, listener:Expr, doBind:Bool):Expr {
var fieldData = warnCheckField(field); var fieldData = warnCheckField(field);
return if (doBind) BindableMacros.bindingSignalProvider.getClassFieldBindExpr(fieldData.e, fieldData.field, listener); var bsp = BindableMacros.bindingSignalProvider;
else BindableMacros.bindingSignalProvider.getClassFieldUnbindExpr(fieldData.e, fieldData.field, listener); return if (doBind) bsp.getClassFieldBindExpr(fieldData.e, fieldData.field, listener);
else bsp.getClassFieldUnbindExpr(fieldData.e, fieldData.field, listener);
} }
static inline function internalBindTo(field:Expr, target:Expr):Expr { static inline function bindTo(field:Expr, target:Expr):Expr {
var fieldData = warnCheckField(field); var fieldData = warnCheckField(field);
return BindableMacros.bindingSignalProvider.getClassFieldBindToExpr(fieldData.e, fieldData.field, target); return BindableMacros.bindingSignalProvider.getClassFieldBindToExpr(fieldData.e, fieldData.field, target);
} }
static inline function internalNotify(field:Expr, ?oldValue:Expr, ?newValue:Expr):Expr { static inline function notify(field:Expr, ?oldValue:Expr, ?newValue:Expr):Expr {
var fieldData = warnCheckField(field); var fieldData = warnCheckField(field);
return BindableMacros.bindingSignalProvider.getClassFieldChangedExpr(fieldData.e, fieldData.field, oldValue, newValue); return BindableMacros.bindingSignalProvider.getClassFieldChangedExpr(fieldData.e, fieldData.field, oldValue, newValue);
} }
static inline function internalUnbindAll(object:ExprOf<IBindable>):Expr { static inline function unbindAll(object:ExprOf<IBindable>):Expr {
var type = Context.typeof(object).follow(); var type = object.deepTypeof();
if (!isBindable(type.getClass())) { if (!isBindable(type.getClass())) {
Context.error('\'${object.toString()}\' must be bindx.IBindable', object.pos); Context.error('\'${object.toString()}\' must be bindx.IBindable', object.pos);
} }
@@ -55,7 +55,7 @@ class BindMacros {
var error:GenericError = null; var error:GenericError = null;
switch (f.expr) { switch (f.expr) {
case EField(e, field): case EField(e, field):
var type = Context.typeof(e); var type = e.deepTypeof();
var classType = switch (type) { case TInst(c, _): c.get(); case _: null; }; var classType = switch (type) { case TInst(c, _): c.get(); case _: null; };
if (classType == null) { if (classType == null) {
error = new FatalError('Type \'${e.toString()}\' is unknown', e.pos); error = new FatalError('Type \'${e.toString()}\' is unknown', e.pos);
+2 -3
View File
@@ -6,9 +6,8 @@ import haxe.macro.Type;
import haxe.macro.Context; import haxe.macro.Context;
import bindx.BindSignal; import bindx.BindSignal;
using bindx.macro.MetaUtils; using bindx.macro.MacroUtils;
using haxe.macro.Tools; using haxe.macro.Tools;
using Lambda;
class BindSignalProvider implements IBindingSignalProvider { class BindSignalProvider implements IBindingSignalProvider {
@@ -113,7 +112,7 @@ class BindSignalProvider implements IBindingSignalProvider {
name: signalName, name: signalName,
kind: FProp("get", "never", type, null), kind: FProp("get", "never", type, null),
pos: field.pos, pos: field.pos,
access: [APrivate], access: [APrivate]
}); });
var getter = macro function foo() { var getter = macro function foo() {
+4 -4
View File
@@ -8,7 +8,7 @@ import haxe.macro.Context;
using haxe.macro.Tools; using haxe.macro.Tools;
using Lambda; using Lambda;
using StringTools; using StringTools;
using bindx.macro.MetaUtils; using bindx.macro.MacroUtils;
class BindableMacros { class BindableMacros {
@@ -191,17 +191,17 @@ class BindableMacros {
static inline function injectBindableMeta(fields:Array<Field>, meta:MetadataEntry):Void { static inline function injectBindableMeta(fields:Array<Field>, meta:MetadataEntry):Void {
for (f in fields) { for (f in fields) {
if (f.hasBindableMeta()) continue; if (f.access.indexOf(APrivate) > -1 || f.hasBindableMeta()) continue;
if (f.access.exists(function (it) return it.equals(APrivate))) continue;
var forceParam = meta.findParam(FORCE); var forceParam = meta.findParam(FORCE);
if (isFieldBindable(f, fields, forceParam.isNotNullAndTrue())) if (isFieldBindable(f, fields, forceParam.isNotNullAndTrue())) {
switch (f.kind) { switch (f.kind) {
case FFun(_): case FFun(_):
case _: f.meta.push({name:MetaUtils.BINDABLE_META, pos:f.pos, params:meta.params}); case _: f.meta.push({name:MetaUtils.BINDABLE_META, pos:f.pos, params:meta.params});
} }
} }
} }
}
static function isFieldBindable(field:Field, fields:Array<Field>, force = false):Bool { static function isFieldBindable(field:Field, fields:Array<Field>, force = false):Bool {
if (field.name == "new") return false; if (field.name == "new") return false;
@@ -1,11 +1,11 @@
package bindx.macro; package bindx.macro;
#if macro
import haxe.macro.Type; import haxe.macro.Type;
import haxe.macro.Expr; import haxe.macro.Expr;
import haxe.macro.Context; import haxe.macro.Context;
using haxe.macro.Tools; using haxe.macro.Tools;
using Lambda;
class MetaUtils { class MetaUtils {
@@ -62,7 +62,7 @@ class ClassTypeMetaUtils {
return bindableMeta(classType) != null; return bindableMeta(classType) != null;
} }
class ExprMetaUtils { class ExprUtils {
static public inline function isTrue(expr:Expr):Bool static public inline function isTrue(expr:Expr):Bool
return expr.expr.match(EConst(CIdent("true"))); return expr.expr.match(EConst(CIdent("true")));
@@ -78,4 +78,13 @@ class ExprMetaUtils {
static public inline function isNullOrTrue(expr:Expr):Bool static public inline function isNullOrTrue(expr:Expr):Bool
return expr == null || isTrue(expr); return expr == null || isTrue(expr);
static public inline function getComplexType(expr:Expr):ComplexType {
return deepTypeof(expr).toComplexType();
}
static public inline function deepTypeof(expr:Expr):haxe.macro.Type {
return Context.typeof(expr).follow();
}
} }
#end
+45 -16
View File
@@ -11,17 +11,17 @@ class BaseTest extends BuddySuite {
public function new() { public function new() {
super(); super();
describe("Using base functionality", { describe("Using base functionality", function () {
var b:Bindable1; var b:Bindable1;
var callNum:Int; var callNum:Int;
before({ before(function () {
b = new Bindable1(); b = new Bindable1();
callNum = 0; callNum = 0;
}); });
it("bindx should bind/unbind fields (lazySignal=true)", { it("bindx should bind/unbind fields (lazySignal=true)", function () {
var strFrom = b.str = "a"; var strFrom = b.str = "a";
var callNum2 = 0; var callNum2 = 0;
@@ -51,7 +51,7 @@ class BaseTest extends BuddySuite {
callNum2.should.be(1); callNum2.should.be(1);
}); });
it("bindx should bind/unbind fields (lazySignal=false)", { it("bindx should bind/unbind fields (lazySignal=false)", function () {
var strFrom = b.str2 = "a"; var strFrom = b.str2 = "a";
var callNum2 = 0; var callNum2 = 0;
@@ -81,7 +81,7 @@ class BaseTest extends BuddySuite {
callNum2.should.be(1); callNum2.should.be(1);
}); });
it("bindx should bind/unbind 'null' values (lazySignal=true)", { it("bindx should bind/unbind 'null' values (lazySignal=true)", function () {
var strFrom = b.str = null; var strFrom = b.str = null;
var callNum2 = 0; var callNum2 = 0;
var listener = function (from:String, to:String) { var listener = function (from:String, to:String) {
@@ -109,7 +109,7 @@ class BaseTest extends BuddySuite {
callNum2.should.be(1); callNum2.should.be(1);
}); });
it("bindx should bind/unbind 'null' values (lazySignal=false)", { it("bindx should bind/unbind 'null' values (lazySignal=false)", function () {
var strFrom = b.str2 = null; var strFrom = b.str2 = null;
var callNum2 = 0; var callNum2 = 0;
var listener = function (from:String, to:String) { var listener = function (from:String, to:String) {
@@ -137,7 +137,7 @@ class BaseTest extends BuddySuite {
callNum2.should.be(1); callNum2.should.be(1);
}); });
it("bindx should bind 2 objects (lazySignal=true)", { it("bindx should bind 2 objects (lazySignal=true)", function() {
var callNum2 = 0; var callNum2 = 0;
var target = {a:""}; var target = {a:""};
var s = ""; var s = "";
@@ -157,7 +157,7 @@ class BaseTest extends BuddySuite {
s.should.be(prev); s.should.be(prev);
}); });
it("bindx should bind 2 objects (lazySignal=false)", { it("bindx should bind 2 objects (lazySignal=false)", function () {
var callNum2 = 0; var callNum2 = 0;
var target = {a:""}; var target = {a:""};
var s = ""; var s = "";
@@ -176,7 +176,7 @@ class BaseTest extends BuddySuite {
s.should.be(prev); s.should.be(prev);
}); });
it("bindx should bind and notify methods (lazySignal=true)", { it("bindx should bind and notify methods (lazySignal=true)", function () {
var listener = function () callNum++; var listener = function () callNum++;
bind(b.bind, listener); bind(b.bind, listener);
Bind.notify(b.bind); Bind.notify(b.bind);
@@ -189,7 +189,7 @@ class BaseTest extends BuddySuite {
callNum.should.be(1); callNum.should.be(1);
}); });
it("bindx should bind and notify methods (lazySignal=false)", { it("bindx should bind and notify methods (lazySignal=false)", function () {
var listener = function () callNum++; var listener = function () callNum++;
bind(b.bind2, listener); bind(b.bind2, listener);
Bind.notify(b.bind2); Bind.notify(b.bind2);
@@ -202,7 +202,7 @@ class BaseTest extends BuddySuite {
callNum.should.be(1); callNum.should.be(1);
}); });
it("bindx should notify properties manual (lazySignal=true)", { it("bindx should notify properties manual (lazySignal=true)", function () {
b.str = "3"; b.str = "3";
var f = "1"; var f = "1";
var t = "2"; var t = "2";
@@ -217,7 +217,7 @@ class BaseTest extends BuddySuite {
callNum.should.be(1); callNum.should.be(1);
}); });
it("bindx should notify properties manual (lazySignal=false)", { it("bindx should notify properties manual (lazySignal=false)", function () {
b.str2 = "3"; b.str2 = "3";
var f = "1"; var f = "1";
var t = "2"; var t = "2";
@@ -232,7 +232,7 @@ class BaseTest extends BuddySuite {
callNum.should.be(1); callNum.should.be(1);
}); });
it("bindx should unbind all properties listeners (lazySignal=true)", { it("bindx should unbind all properties listeners (lazySignal=true)", function () {
bind(b.str, function (from, to) callNum++); bind(b.str, function (from, to) callNum++);
bind(b.str, function (from, to) callNum++); bind(b.str, function (from, to) callNum++);
@@ -242,7 +242,7 @@ class BaseTest extends BuddySuite {
callNum.should.be(0); callNum.should.be(0);
}); });
it("bindx should unbind all properties listeners (lazySignal=false)", { it("bindx should unbind all properties listeners (lazySignal=false)", function () {
bind(b.str2, function (from, to) callNum++); bind(b.str2, function (from, to) callNum++);
bind(b.str2, function (from, to) callNum++); bind(b.str2, function (from, to) callNum++);
@@ -252,7 +252,7 @@ class BaseTest extends BuddySuite {
callNum.should.be(0); callNum.should.be(0);
}); });
it("bindx should unbind all bindings (signal exists) (lazySignal=true/false)", { it("bindx should unbind all bindings (signal exists) (lazySignal=true/false)", function () {
bind(b.str, function (_, _) callNum++); // create binding signal bind(b.str, function (_, _) callNum++); // create binding signal
bind(b.str2, function (_, _) callNum++); bind(b.str2, function (_, _) callNum++);
bind(b.bind, function () callNum++); bind(b.bind, function () callNum++);
@@ -273,7 +273,7 @@ class BaseTest extends BuddySuite {
callNum.should.be(0); callNum.should.be(0);
}); });
it("bindx should unbind all bindings (signal expected) (lazySignal=true/false)", { it("bindx should unbind all bindings (signal expected) (lazySignal=true/false)", function () {
Bind.unbindAll(b); Bind.unbindAll(b);
try { try {
@@ -288,10 +288,39 @@ class BaseTest extends BuddySuite {
true.should.be(true); true.should.be(true);
}); });
it("bindx should resolve typedefs", function () {
var a:TypeBindable1 = new TypeBindable1();
Bind.bind(a.str, function (_, _) {
callNum ++;
});
a.str = "123";
callNum.should.be(1);
});
it("bindx should resolve parametric types", function () {
var b = new GenericBindable<TypeBindable1>();
b.a = new TypeBindable1();
Bind.bind(b.a.str, function (_, _) {
callNum ++;
});
b.a.str = "123";
callNum.should.be(1);
});
}); });
} }
} }
//@:generic
class GenericBindable<A> {
public var a:A;
public function new() {}
}
typedef TypeBindable1 = Bindable1;
class Bindable1 implements bindx.IBindable { class Bindable1 implements bindx.IBindable {
+8 -8
View File
@@ -11,7 +11,7 @@ class ChainBindTest extends BuddySuite {
public function new() { public function new() {
describe("Using BindExt.chain", { describe("Using BindExt.chain", function () {
var from:String; var from:String;
var val:String; var val:String;
@@ -19,7 +19,7 @@ class ChainBindTest extends BuddySuite {
var callNum:Int; var callNum:Int;
var target:{a:String}; var target:{a:String};
before({ before(function () {
from = null; from = null;
val = "a"; val = "a";
b = new BindableChain(4); b = new BindableChain(4);
@@ -27,7 +27,7 @@ class ChainBindTest extends BuddySuite {
callNum = 0; callNum = 0;
}); });
it("BindExt.chain should bind chain changes (unset links)", { it("BindExt.chain should bind chain changes (unset links)", function () {
b.c.c.d = val; b.c.c.d = val;
var listener = function (f:String, t:String) { var listener = function (f:String, t:String) {
@@ -61,7 +61,7 @@ class ChainBindTest extends BuddySuite {
callNum.should.be(5); callNum.should.be(5);
}); });
it("BindExt.chain should bind chain changes (null links)", { it("BindExt.chain should bind chain changes (null links)", function () {
b.c = null; b.c = null;
val = null; val = null;
@@ -84,7 +84,7 @@ class ChainBindTest extends BuddySuite {
callNum.should.be(3); callNum.should.be(3);
}); });
it("BindExt.chain should bind chain changes (0 gap)", { it("BindExt.chain should bind chain changes (0 gap)", function () {
var b2 = new BindableChain(4); var b2 = new BindableChain(4);
b.c.c.f("tada").d = val; b.c.c.f("tada").d = val;
b2.c.c.f("tada").d = val; b2.c.c.f("tada").d = val;
@@ -121,7 +121,7 @@ class ChainBindTest extends BuddySuite {
callNum.should.be(4); callNum.should.be(4);
}); });
it("BindExt.chain should bind chain changes (1 gap)", { it("BindExt.chain should bind chain changes (1 gap)", function () {
b.c.nc.c.f("tada").d = "a"; b.c.nc.c.f("tada").d = "a";
var unbind = BindExt.chain(b.c.nc.c.f("tada").d, function (f:String, t:String) { var unbind = BindExt.chain(b.c.nc.c.f("tada").d, function (f:String, t:String) {
f.should.be(from); f.should.be(from);
@@ -166,7 +166,7 @@ class ChainBindTest extends BuddySuite {
callNum.should.be(3); callNum.should.be(3);
}); });
it("BindExt.chain should bind chain changes (double gap)", { it("BindExt.chain should bind chain changes (double gap)", function () {
b.c.nc.nc.d = "a"; b.c.nc.nc.d = "a";
BindExt.chain(b.c.nc.nc.d, function (f, t:String) { BindExt.chain(b.c.nc.nc.d, function (f, t:String) {
@@ -205,7 +205,7 @@ class ChainBindTest extends BuddySuite {
callNum.should.be(2); callNum.should.be(2);
}); });
it("BindExt.chain should bind default fields", { it("BindExt.chain should bind default fields", function () {
b.d = val = "a"; b.d = val = "a";
var unbind = BindExt.chain(b.d, function (f:String, t:String) { var unbind = BindExt.chain(b.d, function (f:String, t:String) {
+4 -4
View File
@@ -11,18 +11,18 @@ class ExprBindTest extends BuddySuite {
public function new() { public function new() {
describe("Using BindExt.expr", { describe("Using BindExt.expr", function () {
var callNum:Int; var callNum:Int;
var from:String; var from:String;
var target:{a:String}; var target:{a:String};
before({ before(function () {
target = {a:null}; target = {a:null};
from = null; from = null;
callNum = 0; callNum = 0;
}); });
it("BindExt.chain should bind simple expr", { it("BindExt.chain should bind simple expr", function () {
var a = new BaseTest.Bindable1(); var a = new BaseTest.Bindable1();
var b = new BaseTest.Bindable1(); var b = new BaseTest.Bindable1();
a.str = "a1"; a.str = "a1";
@@ -51,7 +51,7 @@ class ExprBindTest extends BuddySuite {
callNum.should.be(3); callNum.should.be(3);
}); });
it("BindExt.chain should bind complex expresions", { it("BindExt.chain should bind complex expresions", function () {
var a = new BaseTest.Bindable1(); var a = new BaseTest.Bindable1();
var b = new BaseTest.Bindable1(); var b = new BaseTest.Bindable1();
var c = new BaseTest.Bindable1(); var c = new BaseTest.Bindable1();
+3 -3
View File
@@ -10,17 +10,17 @@ class ForceTest extends BuddySuite {
public function new() { public function new() {
describe("Using @:bindable(force=true)", { describe("Using @:bindable(force=true)", function () {
var b:BindableForce; var b:BindableForce;
var callNum:Int; var callNum:Int;
before({ before(function () {
b = new BindableForce(); b = new BindableForce();
callNum = 0; callNum = 0;
}); });
it("bindx should correct work with 'force' fields", { it("bindx should correct work with 'force' fields", function () {
Bind.bind(b.str, function (_, _) callNum++); Bind.bind(b.str, function (_, _) callNum++);
Bind.bind(b.str2, function (_, _) callNum++); Bind.bind(b.str2, function (_, _) callNum++);
Bind.bind(b.str3, function (_, _) callNum++); Bind.bind(b.str3, function (_, _) callNum++);
+3 -3
View File
@@ -10,18 +10,18 @@ class InheritanceTest extends BuddySuite {
public function new() { public function new() {
super(); super();
describe("Using classes inheritance", { describe("Using classes inheritance", function () {
var b:BindableChild; var b:BindableChild;
var bp:BindableParent; var bp:BindableParent;
var callNum:Int; var callNum:Int;
before({ before(function () {
b = new BindableChild(); b = new BindableChild();
bp = new BindableParent(); bp = new BindableParent();
callNum = 0; callNum = 0;
}); });
it("bindx should support class/interface inheritance", { it("bindx should support class/interface inheritance", function () {
b.i = 1; b.i = 1;
b.s = "a"; b.s = "a";
Bind.bind(b.i, function (_, _) callNum++); Bind.bind(b.i, function (_, _) callNum++);
+4 -4
View File
@@ -12,13 +12,13 @@ class InlineTest extends BuddySuite {
public function new() { public function new() {
describe("Using @:bindable(inlineSetter=true/false, inlineSignalGetter=true/false)", { describe("Using @:bindable(inlineSetter=true/false, inlineSignalGetter=true/false)", function () {
var b:BindableInline; var b:BindableInline;
var cd:Classdef; var cd:Classdef;
var foundFields:Int; var foundFields:Int;
before({ before(function () {
foundFields = 0; foundFields = 0;
b = new BindableInline(); b = new BindableInline();
var rttiData:String = untyped BindableInline.__rtti; var rttiData:String = untyped BindableInline.__rtti;
@@ -26,7 +26,7 @@ class InlineTest extends BuddySuite {
cd = switch (rtti) { case TClassdecl(c): c; case _: null; }; cd = switch (rtti) { case TClassdecl(c): c; case _: null; };
}); });
it("bindx should generate inline setter", { it("bindx should generate inline setter", function () {
for (c in cd.fields) { for (c in cd.fields) {
switch (c.name) { switch (c.name) {
case "set_str": case "set_str":
@@ -41,7 +41,7 @@ class InlineTest extends BuddySuite {
foundFields.should.be(2); foundFields.should.be(2);
}); });
it("bindx should generate inline signal getter", { it("bindx should generate inline signal getter", function () {
for (c in cd.fields) { for (c in cd.fields) {
switch (c.name) { switch (c.name) {
case "get_str3Changed": case "get_str3Changed":
+5 -5
View File
@@ -10,17 +10,17 @@ class MetaTest extends BuddySuite {
public function new() { public function new() {
describe("Using @bindable meta inheritance", { describe("Using @bindable meta inheritance", function () {
var b:BindableMeta; var b:BindableMeta;
var callNum:Int; var callNum:Int;
before({ before(function () {
b = new BindableMeta(); b = new BindableMeta();
callNum = 0; callNum = 0;
}); });
it("bindx inherit metadata bindable for public fields", { it("bindx inherit metadata bindable for public fields", function () {
b.str = "a"; b.str = "a";
Bind.bind(b.str, function(_, _) callNum++); Bind.bind(b.str, function(_, _) callNum++);
@@ -28,7 +28,7 @@ class MetaTest extends BuddySuite {
callNum.should.be(1); callNum.should.be(1);
}); });
it("bindx inherit metadata bindable for public fields", { it("bindx inherit metadata bindable for public fields", function () {
b.str2 = "a"; b.str2 = "a";
Bind.bind(b.str2, function(_, _) callNum++); Bind.bind(b.str2, function(_, _) callNum++);
@@ -36,7 +36,7 @@ class MetaTest extends BuddySuite {
callNum.should.be(1); callNum.should.be(1);
}); });
it("bindx inherit metadata params", { it("bindx inherit metadata params", function () {
@:privateAccess b.strChanged.should.not.be(null); @:privateAccess b.strChanged.should.not.be(null);
@:privateAccess b.str2Changed.should.not.be(null); @:privateAccess b.str2Changed.should.not.be(null);
}); });
+8 -8
View File
@@ -10,17 +10,17 @@ class SignalTest extends BuddySuite {
public function new() { public function new() {
super(); super();
describe("Using BindSignal", { describe("Using BindSignal", function () {
var fs:FieldSignal<String>; var fs:FieldSignal<String>;
var callNum:Int; var callNum:Int;
before({ before(function () {
fs = new FieldSignal<String>(); fs = new FieldSignal<String>();
callNum = 0; callNum = 0;
}); });
it("signal listeners should listen signal", { it("signal listeners should listen signal", function () {
var f = "1"; var f = "1";
var t = "2"; var t = "2";
function listener(from:String, to:String) { function listener(from:String, to:String) {
@@ -49,7 +49,7 @@ class SignalTest extends BuddySuite {
callNum.should.be(3); callNum.should.be(3);
}); });
it("signal should correct add/remove listeners", { it("signal should correct add/remove listeners", function () {
function listener2(_, _) { function listener2(_, _) {
callNum ++; callNum ++;
} }
@@ -79,7 +79,7 @@ class SignalTest extends BuddySuite {
callNum.should.be(4); // all listeners removed callNum.should.be(4); // all listeners removed
}); });
it("signal should correct dispatch in listener", { it("signal should correct dispatch in listener", function () {
function listener(_, _) { function listener(_, _) {
fs.remove(listener); fs.remove(listener);
fs.dispatch(null, null); fs.dispatch(null, null);
@@ -97,17 +97,17 @@ class SignalTest extends BuddySuite {
}); });
}); });
describe("Using MethodSignal", { describe("Using MethodSignal", function () {
var ms:MethodSignal; var ms:MethodSignal;
var callNum:Int; var callNum:Int;
before({ before(function () {
ms = new MethodSignal(); ms = new MethodSignal();
callNum = 0; callNum = 0;
}); });
it("signal listeners should listen signal", { it("signal listeners should listen signal", function () {
function listener() { function listener() {
callNum ++; callNum ++;
ms.remove(listener); ms.remove(listener);
+14 -14
View File
@@ -10,17 +10,17 @@ class TestProperty extends BuddySuite {
public function new() { public function new() {
super(); super();
describe("Using bind properties", { describe("Using bind properties", function () {
var b:BindableProperty; var b:BindableProperty;
var callNum:Int; var callNum:Int;
before({ before(function () {
b = new BindableProperty(); b = new BindableProperty();
callNum = 0; callNum = 0;
}); });
it("bindx should bind/unbind fields (lazySignal=true)", { it("bindx should bind/unbind fields (lazySignal=true)", function () {
var strFrom = b.str = "a"; var strFrom = b.str = "a";
var callNum2 = 0; var callNum2 = 0;
@@ -50,7 +50,7 @@ class TestProperty extends BuddySuite {
callNum2.should.be(1); callNum2.should.be(1);
}); });
it("bindx should bind/unbind fields (lazySignal=false)", { it("bindx should bind/unbind fields (lazySignal=false)", function () {
var strFrom = b.str2 = "a"; var strFrom = b.str2 = "a";
var callNum2 = 0; var callNum2 = 0;
@@ -80,7 +80,7 @@ class TestProperty extends BuddySuite {
callNum2.should.be(1); callNum2.should.be(1);
}); });
it("bindx should bind/unbind 'null' values (lazySignal=true)", { it("bindx should bind/unbind 'null' values (lazySignal=true)", function () {
var strFrom = b.str = null; var strFrom = b.str = null;
var callNum2 = 0; var callNum2 = 0;
var listener = function (from:String, to:String) { var listener = function (from:String, to:String) {
@@ -108,7 +108,7 @@ class TestProperty extends BuddySuite {
callNum2.should.be(1); callNum2.should.be(1);
}); });
it("bindx should bind/unbind 'null' values (lazySignal=false)", { it("bindx should bind/unbind 'null' values (lazySignal=false)", function () {
var strFrom = b.str2 = null; var strFrom = b.str2 = null;
var callNum2 = 0; var callNum2 = 0;
var listener = function (from:String, to:String) { var listener = function (from:String, to:String) {
@@ -136,7 +136,7 @@ class TestProperty extends BuddySuite {
callNum2.should.be(1); callNum2.should.be(1);
}); });
it("bindx should bind 2 objects (lazySignal=true)", { it("bindx should bind 2 objects (lazySignal=true)", function () {
var callNum2 = 0; var callNum2 = 0;
var target = {a:""}; var target = {a:""};
var s = ""; var s = "";
@@ -156,7 +156,7 @@ class TestProperty extends BuddySuite {
s.should.be(prev); s.should.be(prev);
}); });
it("bindx should bind 2 objects (lazySignal=false)", { it("bindx should bind 2 objects (lazySignal=false)", function () {
var callNum2 = 0; var callNum2 = 0;
var target = {a:""}; var target = {a:""};
var s = ""; var s = "";
@@ -175,7 +175,7 @@ class TestProperty extends BuddySuite {
s.should.be(prev); s.should.be(prev);
}); });
it("bindx should notify properties manual (lazySignal=true)", { it("bindx should notify properties manual (lazySignal=true)", function () {
b.str = "3"; b.str = "3";
var f = "1"; var f = "1";
var t = "2"; var t = "2";
@@ -190,7 +190,7 @@ class TestProperty extends BuddySuite {
callNum.should.be(1); callNum.should.be(1);
}); });
it("bindx should notify properties manual (lazySignal=false)", { it("bindx should notify properties manual (lazySignal=false)", function () {
b.str2 = "3"; b.str2 = "3";
var f = "1"; var f = "1";
var t = "2"; var t = "2";
@@ -205,7 +205,7 @@ class TestProperty extends BuddySuite {
callNum.should.be(1); callNum.should.be(1);
}); });
it("bindx should unbind all properties listeners (lazySignal=true)", { it("bindx should unbind all properties listeners (lazySignal=true)", function () {
bind(b.str, function (from, to) callNum++); bind(b.str, function (from, to) callNum++);
bind(b.str, function (from, to) callNum++); bind(b.str, function (from, to) callNum++);
@@ -215,7 +215,7 @@ class TestProperty extends BuddySuite {
callNum.should.be(0); callNum.should.be(0);
}); });
it("bindx should unbind all properties listeners (lazySignal=false)", { it("bindx should unbind all properties listeners (lazySignal=false)", function () {
bind(b.str2, function (from, to) callNum++); bind(b.str2, function (from, to) callNum++);
bind(b.str2, function (from, to) callNum++); bind(b.str2, function (from, to) callNum++);
@@ -225,7 +225,7 @@ class TestProperty extends BuddySuite {
callNum.should.be(0); callNum.should.be(0);
}); });
it("bindx should unbind all bindings (signal exists) (lazySignal=true/false)", { it("bindx should unbind all bindings (signal exists) (lazySignal=true/false)", function () {
bind(b.str, function (_, _) callNum++); // create binding signal bind(b.str, function (_, _) callNum++); // create binding signal
bind(b.str2, function (_, _) callNum++); bind(b.str2, function (_, _) callNum++);
@@ -242,7 +242,7 @@ class TestProperty extends BuddySuite {
callNum.should.be(0); callNum.should.be(0);
}); });
it("bindx should unbind all bindings (signal expected) (lazySignal=true/false)", { it("bindx should unbind all bindings (signal expected) (lazySignal=true/false)", function () {
Bind.unbindAll(b); Bind.unbindAll(b);
try { try {
+3 -17
View File
@@ -3,12 +3,7 @@ package ;
import buddy.BuddySuite; import buddy.BuddySuite;
import buddy.SuitesRunner; import buddy.SuitesRunner;
class Tests extends BuddySuite { @:build(buddy.GenerateMain.withSuites([
public static function main() {
var reporter = new buddy.reporting.TravisHxReporter();
var runner = new SuitesRunner([
new BaseTest(), new BaseTest(),
new InheritanceTest(), new InheritanceTest(),
new InlineTest(), new InlineTest(),
@@ -17,14 +12,5 @@ class Tests extends BuddySuite {
new TestProperty(), new TestProperty(),
new ChainBindTest(), new ChainBindTest(),
new ExprBindTest(), new ExprBindTest(),
], reporter); ]))
class Tests extends BuddySuite {}
runner.run();
#if sys
Sys.exit(runner.statusCode());
#else
return runner.statusCode();
#end
}
}