private util methods
This commit is contained in:
+6
-6
@@ -37,23 +37,23 @@ class Bind {
|
||||
|
||||
#if macro
|
||||
|
||||
public static function internalBind(field:Expr, listener:Expr, doBind:Bool):Expr {
|
||||
static function internalBind(field:Expr, listener:Expr, doBind:Bool):Expr {
|
||||
var fieldData = warnCheckField(field);
|
||||
return if (doBind) BindMacros.bindingSignalProvider.getClassFieldBindExpr(fieldData.e, fieldData.field, listener);
|
||||
else BindMacros.bindingSignalProvider.getClassFieldUnbindExpr(fieldData.e, fieldData.field, listener);
|
||||
}
|
||||
|
||||
public static function internalBindTo(field:Expr, target:Expr):Expr {
|
||||
static function internalBindTo(field:Expr, target:Expr):Expr {
|
||||
var fieldData = warnCheckField(field);
|
||||
return BindMacros.bindingSignalProvider.getClassFieldBindToExpr(fieldData.e, fieldData.field, target);
|
||||
}
|
||||
|
||||
public static function internalNotify(field:Expr, ?oldValue:Expr, ?newValue:Expr):Expr {
|
||||
static function internalNotify(field:Expr, ?oldValue:Expr, ?newValue:Expr):Expr {
|
||||
var fieldData = warnCheckField(field);
|
||||
return BindMacros.bindingSignalProvider.getClassFieldChangedExpr(fieldData.e, fieldData.field, oldValue, newValue);
|
||||
}
|
||||
|
||||
public static function internalUnbindAll(object:ExprOf<IBindable>):Expr {
|
||||
static function internalUnbindAll(object:ExprOf<IBindable>):Expr {
|
||||
var type = Context.typeof(object).follow();
|
||||
if (!isBindable(type.getClass())) {
|
||||
Context.error('\'${object.toString()}\' must be bindx.IBindable', object.pos);
|
||||
@@ -74,7 +74,7 @@ class Bind {
|
||||
return res;
|
||||
}
|
||||
|
||||
public static function checkField(f:Expr):{e:Expr, field:ClassField, error:bindx.Error} {
|
||||
static function checkField(f:Expr):{e:Expr, field:ClassField, error:bindx.Error} {
|
||||
var error:bindx.Error;
|
||||
switch (f.expr) {
|
||||
case EField(e, field):
|
||||
@@ -108,7 +108,7 @@ class Bind {
|
||||
return {e:f, field:null, error:new bindx.Error('\'${f.toString()}\' is not bindable', f.pos)};
|
||||
}
|
||||
|
||||
public static function isBindable(classType:ClassType):Bool {
|
||||
static function isBindable(classType:ClassType):Bool {
|
||||
var check = [classType];
|
||||
while (check.length > 0) {
|
||||
var t = check.shift();
|
||||
|
||||
@@ -29,6 +29,7 @@ typedef Chain = {
|
||||
#end
|
||||
|
||||
@:access(bindx.BindMacros)
|
||||
@:access(bindx.Bind)
|
||||
class BindExt {
|
||||
|
||||
@:noUsing macro static public function expr<T>(expr:ExprOf<T>, listener:ExprOf<Null<T>->Null<T>->Void>):ExprOf<Void->Void> {
|
||||
@@ -51,7 +52,7 @@ class BindExt {
|
||||
|
||||
#if macro
|
||||
|
||||
public static function internalBindChain(expr:Expr, listener:Expr):Expr {
|
||||
static function internalBindChain(expr:Expr, listener:Expr):Expr {
|
||||
var zeroListener = listenerName(0, "");
|
||||
var chain = null;
|
||||
try { chain = warnPrepareChain(expr, macro $i{ zeroListener }); } catch (e:bindx.Error) e.contextError();
|
||||
@@ -61,7 +62,7 @@ class BindExt {
|
||||
)($listener);
|
||||
}
|
||||
|
||||
public static function internalBindExpr(expr:Expr, listener:Expr):Expr {
|
||||
static function internalBindExpr(expr:Expr, listener:Expr):Expr {
|
||||
var type = Context.typeof(expr).toComplexType();
|
||||
var listenerNameExpr = macro listener;
|
||||
var fieldListenerName = "fieldListener";
|
||||
@@ -146,13 +147,12 @@ class BindExt {
|
||||
|
||||
var zeroListener = listenerName(0, "");
|
||||
var zeroValue = 'value0';
|
||||
chain.unbind.unshift(macro $i { zeroValue } = null);
|
||||
|
||||
var callListener = switch (type) {
|
||||
case macro : Void: macro if (!init) $i{zeroListener}();
|
||||
case _: macro if (!init) { var v:Null<$type> = null; try { v = $expr; } catch (e:Dynamic) { }; $i{zeroListener}($i{zeroValue}, $i{zeroValue} = v); };
|
||||
}
|
||||
|
||||
chain.unbind.unshift(macro $i{zeroValue} = null);
|
||||
|
||||
var preInit = [
|
||||
(macro var init:Bool = true),
|
||||
@@ -203,7 +203,6 @@ class BindExt {
|
||||
}
|
||||
prevField = field;
|
||||
}
|
||||
|
||||
return fields;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import haxe.macro.Expr;
|
||||
import haxe.macro.Type;
|
||||
|
||||
interface IBindingSignalProvider {
|
||||
|
||||
|
||||
function getFieldDispatcher(field:Field, result:Array<Field>):Void;
|
||||
function getFieldChangedExpr(field:Field, oldValue:Expr, newValue:Expr):Expr;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user