Skip to content

Commit

Permalink
Merge pull request #1047 from sveltejs/gh-1040
Browse files Browse the repository at this point in the history
create initial data for dynamic components in correct place
  • Loading branch information
Rich-Harris authored Dec 24, 2017
2 parents 8472142 + 7a8e177 commit db64694
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/generators/nodes/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,13 @@ export default class Component extends Node {
var ${switch_vars.value} = ${snippet};
function ${switch_vars.props}(${params}) {
${statements.length > 0 && statements.join('\n')}
return {
${componentInitProperties.join(',\n')}
};
}
if (${switch_vars.value}) {
${statements.length > 0 && statements.join('\n')}
var ${name} = new ${expression}(${switch_vars.props}(${params}));
${beforecreate}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>green {{foo}}</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>red {{foo}}</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export default {
data: {
x: true,
foo: 'one'
},

html: `
<p>green one</p>
`,

test(assert, component, target) {
component.set({
x: false
});

assert.htmlEqual(target.innerHTML, `
<p>red one</p>
`);

component.set({
x: true,
foo: 'two'
});

assert.htmlEqual(target.innerHTML, `
<p>green two</p>
`);
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<:Component {x ? Green : Red} bind:foo />

<script>
import Green from './Green.html';
import Red from './Red.html';

export default {
data() {
return {
Green,
Red
};
}
};
</script>

0 comments on commit db64694

Please sign in to comment.