allow access to Bind from another macroses
This commit is contained in:
+11
-14
@@ -15,28 +15,28 @@ using Lambda;
|
|||||||
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 _bind(field, listener, true);
|
return internalBind(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 _bindTo(field, target);
|
return internalBindTo(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 _bind(field, listener, false);
|
return internalBind(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 _notify(field, oldValue, newValue);
|
return internalNotify(field, oldValue, newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@:noUsing macro static public function disposeBindings(object:ExprOf<IBindable>):Expr {
|
@:noUsing macro static public function disposeBindings(object:ExprOf<IBindable>):Expr {
|
||||||
return _disposeBindings(object);
|
return internalDisposeBindings(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if macro
|
#if macro
|
||||||
|
|
||||||
static function _bind(field:Expr, listener:Expr, doBind:Bool):Expr {
|
public static function internalBind(field:Expr, listener:Expr, doBind:Bool):Expr {
|
||||||
var fieldData = checkField(field);
|
var fieldData = checkField(field);
|
||||||
return if (fieldData != null) {
|
return if (fieldData != null) {
|
||||||
if (doBind) BindMacros.bindingSignalProvider.getClassFieldBindExpr(fieldData.e, fieldData.field, listener);
|
if (doBind) BindMacros.bindingSignalProvider.getClassFieldBindExpr(fieldData.e, fieldData.field, listener);
|
||||||
@@ -44,17 +44,17 @@ class Bind {
|
|||||||
} else macro {};
|
} else macro {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static function _bindTo(field:Expr, target:Expr):Expr {
|
public static function internalBindTo(field:Expr, target:Expr):Expr {
|
||||||
var fieldData = checkField(field);
|
var fieldData = checkField(field);
|
||||||
return BindMacros.bindingSignalProvider.getClassFieldBindToExpr(fieldData.e, fieldData.field, target);
|
return BindMacros.bindingSignalProvider.getClassFieldBindToExpr(fieldData.e, fieldData.field, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function _notify(field:Expr, ?oldValue:Expr, ?newValue:Expr):Expr {
|
public static function internalNotify(field:Expr, ?oldValue:Expr, ?newValue:Expr):Expr {
|
||||||
var fieldData = checkField(field);
|
var fieldData = checkField(field);
|
||||||
return BindMacros.bindingSignalProvider.getClassFieldChangedExpr(fieldData.e, fieldData.field, oldValue, newValue);
|
return BindMacros.bindingSignalProvider.getClassFieldChangedExpr(fieldData.e, fieldData.field, oldValue, newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function _disposeBindings(object:ExprOf<IBindable>):Expr {
|
public static function internalDisposeBindings(object:ExprOf<IBindable>):Expr {
|
||||||
var type = Context.typeof(object).follow();
|
var type = Context.typeof(object).follow();
|
||||||
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);
|
||||||
@@ -62,7 +62,7 @@ class Bind {
|
|||||||
return BindMacros.bindingSignalProvider.getDisposeBindingsExpr(object, type);
|
return BindMacros.bindingSignalProvider.getDisposeBindingsExpr(object, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
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).getClass();
|
||||||
@@ -93,10 +93,7 @@ class Bind {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
static var IBindableType = macro : bindx.IBindable;
|
public static function isBindable(classType:ClassType):Bool {
|
||||||
|
|
||||||
static function isBindable(classType:ClassType) {
|
|
||||||
|
|
||||||
var t = classType;
|
var t = classType;
|
||||||
while (t != null) {
|
while (t != null) {
|
||||||
for (it in t.interfaces) {
|
for (it in t.interfaces) {
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package bindx;
|
package bindx;
|
||||||
|
|
||||||
|
#if macro
|
||||||
|
|
||||||
import bindx.BindSignal.BindSignalProvider;
|
import bindx.BindSignal.BindSignalProvider;
|
||||||
import bindx.BindSignal.Signal;
|
import bindx.BindSignal.Signal;
|
||||||
import haxe.macro.Expr;
|
import haxe.macro.Expr;
|
||||||
@@ -13,8 +15,6 @@ using Lambda;
|
|||||||
|
|
||||||
class BindSignalProvider implements IBindingSignalProvider {
|
class BindSignalProvider implements IBindingSignalProvider {
|
||||||
|
|
||||||
#if macro
|
|
||||||
|
|
||||||
static inline var SIGNAL_POSTFIX = "Changed";
|
static inline var SIGNAL_POSTFIX = "Changed";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -166,9 +166,10 @@ class BindSignalProvider implements IBindingSignalProvider {
|
|||||||
@:expose inline function hasLazy(meta:MetadataEntry) {
|
@:expose inline function hasLazy(meta:MetadataEntry) {
|
||||||
return meta.findParam(LAZY_SIGNAL).isNullOrTrue();
|
return meta.findParam(LAZY_SIGNAL).isNullOrTrue();
|
||||||
}
|
}
|
||||||
#end
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#end
|
||||||
|
|
||||||
class MethodSignal extends Signal<Void -> Void> {
|
class MethodSignal extends Signal<Void -> Void> {
|
||||||
|
|
||||||
public function dispatch():Void {
|
public function dispatch():Void {
|
||||||
|
|||||||
Reference in New Issue
Block a user