From 192d6e40b0fafb87c9e89976687ec7d0e647bb92 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 11 Jul 2017 08:54:36 -0400 Subject: [PATCH] almost all tests passing again --- src/generators/dom/index.ts | 2 +- .../dom/visitors/Component/Binding.ts | 20 ++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/generators/dom/index.ts b/src/generators/dom/index.ts index b620444b2a..e6635235fa 100644 --- a/src/generators/dom/index.ts +++ b/src/generators/dom/index.ts @@ -234,7 +234,7 @@ export default function dom( @template.oncreate.call( this ); }`} - ${generator.hasIntroTransitions && `@callAll(this._postcreate);`} + ${(generator.hasComplexBindings || generator.hasIntroTransitions) && `@callAll(this._postcreate);`} } @assign( ${prototypeBase}, ${proto}); diff --git a/src/generators/dom/visitors/Component/Binding.ts b/src/generators/dom/visitors/Component/Binding.ts index 3fedce450e..c9df47b2f5 100644 --- a/src/generators/dom/visitors/Component/Binding.ts +++ b/src/generators/dom/visitors/Component/Binding.ts @@ -66,19 +66,25 @@ export default function visitBinding( const updating = block.getUniqueName(`${local.name}_updating`); block.addVariable(updating, 'false'); + const observer = block.getUniqueName('observer'); + const value = block.getUniqueName('value'); + local.create.addBlock(deindent` - ${local.name}.observe( '${attribute.name}', function ( value ) { + function ${observer} ( value ) { if ( ${updating} ) return; ${updating} = true; ${setter} ${updating} = false; - }, { init: false }); - - if ( @differs( ${local.name}.get( '${attribute.name}' ), ${snippet} ) ) { - #component._postcreate.push( function () { - ${setter} - }); } + + ${local.name}.observe( '${attribute.name}', ${observer}, { init: false }); + + #component._postcreate.push( function () { + var value = ${local.name}.get( '${attribute.name}' ); + if ( @differs( value, ${snippet} ) ) { + ${observer}.call( ${local.name}, value ); + } + }); `); local.update.addBlock(deindent`