From cffbc15150c8721c792694bfc90a58acaed896a5 Mon Sep 17 00:00:00 2001 From: Dima Granetchi Date: Wed, 26 Nov 2014 14:20:50 +0200 Subject: [PATCH] expr bind old value --- src/bindx/BindxExt.hx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/bindx/BindxExt.hx b/src/bindx/BindxExt.hx index b3759ad..ffe5df5 100644 --- a/src/bindx/BindxExt.hx +++ b/src/bindx/BindxExt.hx @@ -131,18 +131,21 @@ class BindExt { Context.warning('Bind \'${msg.join("', '")}\'', expr.pos); var zeroListener = listenerName(0, ""); + var zeroValue = 'value0'; 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}(null, v); }; + 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 init = [ macro function $fieldListenerName(?from:Dynamic, ?to:Dynamic) $callListener, macro function $methodListenerName() $callListener ]; - init = [macro var init:Bool = true].concat(chain.init).concat(init).concat(chain.bind); + init = [(macro var init:Bool = true), macro var $zeroValue:Null<$type> = null].concat(chain.init).concat(init).concat(chain.bind); var res = macro (function ($zeroListener):Void->Void $b { init.concat([macro init = false, macro $i{methodListenerName}(), macro return function ():Void $b { chain.unbind }]) }