Skip to content

Commit

Permalink
Reapply sveltejs#3128 changes to new interfaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
campbeln committed Feb 10, 2020
1 parent c323282 commit 3898b05
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/compiler/compile/render_dom/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,12 @@ export default function dom(
@insert(options.target, this, options.anchor);
}
this.$$.slotted = {};
${(props.length > 0 || uses_props) && b`
for (const key in options.props.$$slots) {
this.$$.slotted[key] = options.props.$$slots[key][0]();
this.$$.slotted[key].c();
}
if (options.props) {
this.$set(options.props);
@flush();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,12 @@ export default class InlineComponentWrapper extends Wrapper {
}

block.chunks.mount.push(b`
if (${name}) {
if (component.compile_options.customElement) {
block.chunks.mount.push(
@insert(${parent_node || '#target'}, ${name}, ${parent_node ? 'null' : 'anchor'});
)
}
else if (${name}) {
@mount_component(${name}, ${parent_node || '#target'}, ${parent_node ? 'null' : 'anchor'});
}
`);
Expand Down
8 changes: 7 additions & 1 deletion src/runtime/internal/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ if (typeof HTMLElement === 'function') {
// @ts-ignore todo: improve typings
for (const key in this.$$.slotted) {
// @ts-ignore todo: improve typings
this.appendChild(this.$$.slotted[key]);
//this.appendChild(this.$$.slotted[key]);
this.$$.slotted[key].m(this, null);
}
}

Expand All @@ -183,6 +184,11 @@ if (typeof HTMLElement === 'function') {
}

$destroy() {
// @ts-ignore todo: improve typings
for (const key in this.$$.slotted) {
// @ts-ignore todo: improve typings
this.$$.slotted[key].d();
}
destroy_component(this, 1);
this.$destroy = noop;
}
Expand Down

0 comments on commit 3898b05

Please sign in to comment.