From 74d5e72f1887598caa9a37f814824a4a00306d82 Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Tue, 18 Jun 2019 21:55:27 -0400 Subject: [PATCH] argh so close --- .../render-dom/wrappers/InlineComponent/index.ts | 8 ++++---- src/compiler/compile/render-dom/wrappers/Slot.ts | 2 +- src/runtime/internal/Component.ts | 12 +++++------- src/runtime/internal/transitions.ts | 2 +- test/js/samples/component-static-array/expected.js | 3 ++- .../samples/component-static-immutable/expected.js | 3 ++- .../samples/component-static-immutable2/expected.js | 3 ++- test/js/samples/component-static/expected.js | 3 ++- test/js/samples/debug-empty/expected.js | 2 +- test/js/samples/debug-foo-bar-baz-things/expected.js | 4 ++-- test/js/samples/debug-foo/expected.js | 4 ++-- .../dev-warning-missing-data-computed/expected.js | 2 +- test/js/samples/dynamic-import/expected.js | 3 ++- test/js/samples/non-imported-component/expected.js | 5 +++-- 14 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/compiler/compile/render-dom/wrappers/InlineComponent/index.ts b/src/compiler/compile/render-dom/wrappers/InlineComponent/index.ts index 43112d5ca1..b5c29cf0ac 100644 --- a/src/compiler/compile/render-dom/wrappers/InlineComponent/index.ts +++ b/src/compiler/compile/render-dom/wrappers/InlineComponent/index.ts @@ -424,7 +424,7 @@ export default class InlineComponentWrapper extends Wrapper { @group_outros(); const old_component = ${name}; @transition_out(old_component.$$.fragment, 1, 1, () => { - @destroy(old_component); + @destroy_component(old_component); }); @check_outros(); } @@ -457,10 +457,10 @@ export default class InlineComponentWrapper extends Wrapper { } block.builders.outro.add_line( - `if (${name}) @transition_out(${name}.$$.fragment, #local);` + `if (${name}) @transition_out(${name}.$$.fragment, 0, #local);` ); - block.builders.destroy.add_line(`if (${name}) ${name}.$destroy(${parent_node ? '' : 'detaching'});`); + block.builders.destroy.add_line(`if (${name}) @destroy_component(${name}, ${parent_node ? '' : 'detaching'});`); } else { const expression = this.node.name === 'svelte:self' ? '__svelte:self__' // TODO conflict-proof this @@ -500,7 +500,7 @@ export default class InlineComponentWrapper extends Wrapper { } block.builders.destroy.add_block(deindent` - ${name}.$destroy(${parent_node ? '' : 'detaching'}); + @destroy_component(${name}, ${parent_node ? '' : 'detaching'}); `); block.builders.outro.add_line( diff --git a/src/compiler/compile/render-dom/wrappers/Slot.ts b/src/compiler/compile/render-dom/wrappers/Slot.ts index 3376a797b8..cef9e98778 100644 --- a/src/compiler/compile/render-dom/wrappers/Slot.ts +++ b/src/compiler/compile/render-dom/wrappers/Slot.ts @@ -146,7 +146,7 @@ export default class SlotWrapper extends Wrapper { ); block.builders.outro.add_line( - `@transition_out(${slot}, #local);` + `@transition_out(${slot}, 0, #local);` ); let update_conditions = [...this.dependencies].map(name => `changed.${name}`).join(' || '); diff --git a/src/runtime/internal/Component.ts b/src/runtime/internal/Component.ts index 7da7e355d7..373dc31f0d 100644 --- a/src/runtime/internal/Component.ts +++ b/src/runtime/internal/Component.ts @@ -50,10 +50,12 @@ export function mount_component(component, target, anchor) { after_render.forEach(add_render_callback); } -export function destroy(component) { +export function destroy_component(component, detaching) { if (component.$$) { run_all(component.$$.on_destroy); + if (detaching) component.$$.fragment.d(1); + // TODO null out other refs, including component.$$ (but need to // preserve final state?) component.$$.on_destroy = component.$$.fragment = null; @@ -153,9 +155,7 @@ if (typeof HTMLElement !== 'undefined') { } $destroy() { - const { fragment } = this.$$; - destroy(this); - fragment.d(1); + destroy_component(this, 1); this.$destroy = noop; } @@ -180,9 +180,7 @@ export class SvelteComponent { $$: T$$; $destroy() { - const { fragment } = this.$$; - destroy(this); - fragment.d(1); + destroy_component(this, 1); this.$destroy = noop; } diff --git a/src/runtime/internal/transitions.ts b/src/runtime/internal/transitions.ts index 7372b9f058..0932ed45ad 100644 --- a/src/runtime/internal/transitions.ts +++ b/src/runtime/internal/transitions.ts @@ -53,7 +53,7 @@ export function transition_out(block, detaching: 0 | 1, local: 0 | 1, callback) outroing.add(block); outros.callbacks.push(() => { outroing.delete(block); - if (local) block.d(detaching); + if (detaching) block.d(detaching); if (callback) callback(); }); diff --git a/test/js/samples/component-static-array/expected.js b/test/js/samples/component-static-array/expected.js index 595b392e50..7f92ebe479 100644 --- a/test/js/samples/component-static-array/expected.js +++ b/test/js/samples/component-static-array/expected.js @@ -1,6 +1,7 @@ /* generated by Svelte vX.Y.Z */ import { SvelteComponent, + destroy_component, init, mount_component, noop, @@ -39,7 +40,7 @@ function create_fragment(ctx) { }, d(detaching) { - nested.$destroy(detaching); + destroy_component(nested, detaching); } }; } diff --git a/test/js/samples/component-static-immutable/expected.js b/test/js/samples/component-static-immutable/expected.js index 88e8370171..30706bad4e 100644 --- a/test/js/samples/component-static-immutable/expected.js +++ b/test/js/samples/component-static-immutable/expected.js @@ -1,6 +1,7 @@ /* generated by Svelte vX.Y.Z */ import { SvelteComponent, + destroy_component, init, mount_component, noop, @@ -39,7 +40,7 @@ function create_fragment(ctx) { }, d(detaching) { - nested.$destroy(detaching); + destroy_component(nested, detaching); } }; } diff --git a/test/js/samples/component-static-immutable2/expected.js b/test/js/samples/component-static-immutable2/expected.js index 88e8370171..30706bad4e 100644 --- a/test/js/samples/component-static-immutable2/expected.js +++ b/test/js/samples/component-static-immutable2/expected.js @@ -1,6 +1,7 @@ /* generated by Svelte vX.Y.Z */ import { SvelteComponent, + destroy_component, init, mount_component, noop, @@ -39,7 +40,7 @@ function create_fragment(ctx) { }, d(detaching) { - nested.$destroy(detaching); + destroy_component(nested, detaching); } }; } diff --git a/test/js/samples/component-static/expected.js b/test/js/samples/component-static/expected.js index 515a75f26a..d26aa47e30 100644 --- a/test/js/samples/component-static/expected.js +++ b/test/js/samples/component-static/expected.js @@ -1,6 +1,7 @@ /* generated by Svelte vX.Y.Z */ import { SvelteComponent, + destroy_component, init, mount_component, noop, @@ -39,7 +40,7 @@ function create_fragment(ctx) { }, d(detaching) { - nested.$destroy(detaching); + destroy_component(nested, detaching); } }; } diff --git a/test/js/samples/debug-empty/expected.js b/test/js/samples/debug-empty/expected.js index 6c29ad5639..6f07993590 100644 --- a/test/js/samples/debug-empty/expected.js +++ b/test/js/samples/debug-empty/expected.js @@ -53,7 +53,7 @@ function create_fragment(ctx) { i: noop, o: noop, - d: function destroy_1(detaching) { + d: function destroy(detaching) { if (detaching) { detach(h1); detach(t3); diff --git a/test/js/samples/debug-foo-bar-baz-things/expected.js b/test/js/samples/debug-foo-bar-baz-things/expected.js index 0d7238541f..eea35d5ba7 100644 --- a/test/js/samples/debug-foo-bar-baz-things/expected.js +++ b/test/js/samples/debug-foo-bar-baz-things/expected.js @@ -59,7 +59,7 @@ function create_each_block(ctx) { } }, - d: function destroy_1(detaching) { + d: function destroy(detaching) { if (detaching) { detach(span); detach(t1); @@ -137,7 +137,7 @@ function create_fragment(ctx) { i: noop, o: noop, - d: function destroy_1(detaching) { + d: function destroy(detaching) { destroy_each(each_blocks, detaching); if (detaching) { diff --git a/test/js/samples/debug-foo/expected.js b/test/js/samples/debug-foo/expected.js index 446a8d9a71..5b931d9464 100644 --- a/test/js/samples/debug-foo/expected.js +++ b/test/js/samples/debug-foo/expected.js @@ -59,7 +59,7 @@ function create_each_block(ctx) { } }, - d: function destroy_1(detaching) { + d: function destroy(detaching) { if (detaching) { detach(span); detach(t1); @@ -137,7 +137,7 @@ function create_fragment(ctx) { i: noop, o: noop, - d: function destroy_1(detaching) { + d: function destroy(detaching) { destroy_each(each_blocks, detaching); if (detaching) { diff --git a/test/js/samples/dev-warning-missing-data-computed/expected.js b/test/js/samples/dev-warning-missing-data-computed/expected.js index c8d1cad60a..5c4b2ece1b 100644 --- a/test/js/samples/dev-warning-missing-data-computed/expected.js +++ b/test/js/samples/dev-warning-missing-data-computed/expected.js @@ -52,7 +52,7 @@ function create_fragment(ctx) { i: noop, o: noop, - d: function destroy_1(detaching) { + d: function destroy(detaching) { if (detaching) { detach(p); } diff --git a/test/js/samples/dynamic-import/expected.js b/test/js/samples/dynamic-import/expected.js index c92ad06f9f..9892f63734 100644 --- a/test/js/samples/dynamic-import/expected.js +++ b/test/js/samples/dynamic-import/expected.js @@ -1,6 +1,7 @@ /* generated by Svelte vX.Y.Z */ import { SvelteComponent, + destroy_component, init, mount_component, noop, @@ -40,7 +41,7 @@ function create_fragment(ctx) { }, d(detaching) { - lazyload.$destroy(detaching); + destroy_component(lazyload, detaching); } }; } diff --git a/test/js/samples/non-imported-component/expected.js b/test/js/samples/non-imported-component/expected.js index 71dd5d5030..b990d3b76d 100644 --- a/test/js/samples/non-imported-component/expected.js +++ b/test/js/samples/non-imported-component/expected.js @@ -1,6 +1,7 @@ /* generated by Svelte vX.Y.Z */ import { SvelteComponent, + destroy_component, detach, init, insert, @@ -52,13 +53,13 @@ function create_fragment(ctx) { }, d(detaching) { - imported.$destroy(detaching); + destroy_component(imported, detaching); if (detaching) { detach(t); } - nonimported.$destroy(detaching); + destroy_component(nonimported, detaching); } }; }