From 7a3611b5df3c63a0d70256ea94742eb1f4c89257 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Sun, 16 Apr 2017 20:41:28 -0400 Subject: [PATCH] wait this is actually way easier --- .../dom/visitors/Component/Binding.js | 21 ++----------------- .../dom/visitors/shared/binding/getSetter.js | 2 +- .../samples/component-binding-each/_config.js | 2 +- 3 files changed, 4 insertions(+), 21 deletions(-) diff --git a/src/generators/dom/visitors/Component/Binding.js b/src/generators/dom/visitors/Component/Binding.js index a689731c87..b435b064bc 100644 --- a/src/generators/dom/visitors/Component/Binding.js +++ b/src/generators/dom/visitors/Component/Binding.js @@ -1,6 +1,6 @@ import deindent from '../../../../utils/deindent.js'; import flattenReference from '../../../../utils/flattenReference.js'; -import getSetter, { getTailSnippet } from '../shared/binding/getSetter.js'; +import getSetter from '../shared/binding/getSetter.js'; export default function visitBinding ( generator, block, state, node, attribute, local ) { const { name, keypath } = flattenReference( attribute.value ); @@ -41,8 +41,6 @@ export default function visitBinding ( generator, block, state, node, attribute, const updating = block.getUniqueName( `${local.name}_updating` ); - const initialValue = getInitialValue({ block, local, attribute, name }); - local.create.addBlock( deindent` var ${updating} = false; @@ -53,7 +51,7 @@ export default function visitBinding ( generator, block, state, node, attribute, ${updating} = true; ${setter} ${updating} = false; - }, { init: ${generator.helper( 'differs' )}( ${local.name}.get( '${attribute.name}' ), ${initialValue} ) }); + }, { init: ${generator.helper( 'differs' )}( ${local.name}.get( '${attribute.name}' ), ${snippet} ) }); }); ` ); @@ -64,19 +62,4 @@ export default function visitBinding ( generator, block, state, node, attribute, ${updating} = false; } ` ); -} - -function getInitialValue ({ block, local, attribute, name }) { - const tail = attribute.value.type === 'MemberExpression' ? getTailSnippet( attribute.value ) : ''; - - if ( block.contexts.has( name ) ) { - // const prop = dependencies[0]; - - const list = `${local.name}._context.${block.listNames.get( name )}`; - const index = `${local.name}._context.${block.indexNames.get( name )}`; - - return `${list}[${index}]${tail}`; - } - - return `${block.component}.get( '${name}' )${tail}`; } \ No newline at end of file diff --git a/src/generators/dom/visitors/shared/binding/getSetter.js b/src/generators/dom/visitors/shared/binding/getSetter.js index 30be314287..852ea83fa7 100644 --- a/src/generators/dom/visitors/shared/binding/getSetter.js +++ b/src/generators/dom/visitors/shared/binding/getSetter.js @@ -25,7 +25,7 @@ export default function getSetter ({ block, name, keypath, context, attribute, d return `${block.component}._set({ ${name}: ${value} });`; } -export function getTailSnippet ( node ) { +function getTailSnippet ( node ) { const end = node.end; while ( node.type === 'MemberExpression' ) node = node.object; const start = node.end; diff --git a/test/runtime/samples/component-binding-each/_config.js b/test/runtime/samples/component-binding-each/_config.js index d42460aff0..632898eb5a 100644 --- a/test/runtime/samples/component-binding-each/_config.js +++ b/test/runtime/samples/component-binding-each/_config.js @@ -16,7 +16,7 @@ export default {

blah, bar, baz

` ); - + component.destroy(); } };