Skip to content

create initial data for dynamic components in correct place #1047

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
create initial data for dynamic components in correct place - fixes #…
  • Loading branch information
Rich-Harris committed Dec 24, 2017
commit 7a8e17779ce43e951106ebfd4c628d77507bd7a4
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>