fix two-way binding for components inside each-blocks - closes #356

pull/357/head
Rich-Harris 8 years ago
parent df70e7b059
commit 92925ede0d

@ -127,8 +127,10 @@ export default function createBinding ( generator, node, attribute, current, loc
});
` );
const dependencies = parts[0] in current.contexts ? current.contextDependencies[ parts[0] ] : [ parts[0] ];
local.update.addBlock( deindent`
if ( !${local.name}_updating && '${parts[0]}' in changed ) {
if ( !${local.name}_updating && ${dependencies.map( dependency => `'${dependency}' in changed` ).join( '||' )} ) {
${local.name}._set({ ${attribute.name}: ${contextual ? attribute.value : `root.${attribute.value}`} });
}
` );

@ -41,6 +41,11 @@ export default {
return `${attribute.name}: ${value}`;
})
.concat( bindings.map( binding => {
const parts = binding.value.split( '.' );
const value = parts[0] in generator.current.contexts ? binding.value : `root.${binding.value}`;
return `${binding.name}: ${value}`;
}))
.join( ', ' );
const expression = node.name === ':Self' ? generator.name : `template.components.${node.name}`;

@ -0,0 +1,24 @@
export default {
data: {
a: [{ id: 'foo' }, { id: 'bar' }, { id: 'baz' }]
},
html: `
<span>foo</span><span>bar</span><span>baz</span>
`,
test ( assert, component, target ) {
component.set({
a: [
{ id: 'yep' },
{ id: 'nope' }
]
});
assert.htmlEqual( target.innerHTML, `
<span>yep</span><span>nope</span>
` );
component.destroy();
}
};

@ -0,0 +1,13 @@
{{#each a as x}}
<Widget bind:value='x'/>
{{/each}}
<script>
import Widget from './Widget.html';
export default {
components: {
Widget
}
};
</script>
Loading…
Cancel
Save