Skip to content

Commit

Permalink
Merge pull request #728 from sveltejs/gh-721
Browse files Browse the repository at this point in the history
use _set, not set, when updating child components
  • Loading branch information
Rich-Harris authored Jul 29, 2017
2 parents dbf635b + cb030fd commit 57e7f75
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/generators/dom/visitors/Component/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export default function visitComponent(
${updates.join('\n')}
if ( Object.keys( ${name}_changes ).length ) ${name}.set( ${name}_changes );
if ( Object.keys( ${name}_changes ).length ) ${name}._set( ${name}_changes );
`);
}

Expand Down
18 changes: 18 additions & 0 deletions test/runtime/samples/component-binding-blowback-c/Nested.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<li>
{{yield}}
</li>

<script>
const initialValues = {
'id-0': 'zero',
'id-1': 'one',
'id-2': 'two',
'id-3': 'three'
};

export default {
oncreate() {
this.set({ value: initialValues[this.get('id')] });
}
};
</script>
33 changes: 33 additions & 0 deletions test/runtime/samples/component-binding-blowback-c/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
export default {
'skip-ssr': true,

data: {
count: 3
},

html: `
<input type='number'>
<ol>
<li>id-2: value is two</li>
<li>id-1: value is one</li>
<li>id-0: value is zero</li>
</ol>
`,

test (assert, component, target, window) {
const input = target.querySelector('input');

input.value = 4;
input.dispatchEvent(new window.Event('input'));

assert.htmlEqual(target.innerHTML, `
<input type='number'>
<ol>
<li>id-3: value is three</li>
<li>id-2: value is two</li>
<li>id-1: value is one</li>
<li>id-0: value is zero</li>
</ol>
`);
}
};
34 changes: 34 additions & 0 deletions test/runtime/samples/component-binding-blowback-c/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<input type='number' bind:value='count'>

<ol>
{{#each ids as object @id}}
<Nested bind:value='idToValue[object.id]' id='{{object.id}}'>
{{object.id}}: value is {{idToValue[object.id]}}
</Nested>
{{/each}}
</ol>

<script>
import Nested from './Nested.html';

export default {
data() {
return {
idToValue: Object.create(null)
};
},

computed: {
ids(count) {
return new Array(count)
.fill(null)
.map((_, i) => ({ id: 'id-' + i}))
.reverse();
}
},

components: {
Nested
}
};
</script>

0 comments on commit 57e7f75

Please sign in to comment.