mirror of
https://github.com/sveltejs/svelte.git
synced 2024-12-01 17:30:59 +01:00
Merge pull request #357 from sveltejs/gh-356
fix two-way binding for components inside each-blocks
This commit is contained in:
commit
be8efcc9f2
@ -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}`} });
|
||||
}
|
||||
` );
|
||||
@ -151,7 +153,6 @@ export default function createBinding ( generator, node, attribute, current, loc
|
||||
|
||||
updateElement = deindent`
|
||||
var ${value} = ${contextual ? attribute.value : `root.${attribute.value}`};
|
||||
console.log( 'value', ${value} );
|
||||
for ( var ${i} = 0; ${i} < ${local.name}.options.length; ${i} += 1 ) {
|
||||
var ${option} = ${local.name}.options[${i}];
|
||||
|
||||
|
@ -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 @@
|
||||
<span>{{value.id}}</span>
|
@ -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…
Reference in New Issue
Block a user