fix dynamic components inside elements - fixes #994

pull/1004/head
Rich Harris 7 years ago committed by GitHub
parent a8eaa7e95c
commit e20b38e7c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -289,6 +289,8 @@ export default class Component extends Node {
`if (${name}) ${name}._mount(${parentNode || '#target'}, ${parentNode ? 'null' : 'anchor'});`
);
const updateMountNode = this.getUpdateMountNode(anchor);
block.builders.update.addBlock(deindent`
if (${switch_vars.value} !== (${switch_vars.value} = ${snippet})) {
if (${name}) ${name}.destroy();
@ -298,7 +300,7 @@ export default class Component extends Node {
${name}._fragment.c();
${this.children.map(child => remount(generator, child, name))}
${name}._mount(${anchor}.parentNode, ${anchor});
${name}._mount(${updateMountNode}, ${anchor});
${eventHandlers.map(handler => deindent`
${name}.on("${handler.name}", ${handler.var});

@ -0,0 +1,19 @@
export default {
data: {
x: true
},
html: `
<div><p>true, therefore Foo</p></div>
`,
test(assert, component, target) {
component.set({
x: false
});
assert.htmlEqual(target.innerHTML, `
<div><p>false, therefore Bar</p></div>
`);
}
};

@ -0,0 +1,14 @@
<div>
<:Component { x ? Foo : Bar } x='{{x}}'/>
</div>
<script>
import Foo from './Foo.html';
import Bar from './Bar.html';
export default {
data() {
return { Foo, Bar };
}
};
</script>
Loading…
Cancel
Save