Merge pull request from sveltejs/gh-3058

always run onDestroy functions
pull/3101/head
Rich Harris 6 years ago committed by GitHub
commit 8431aff34f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -54,7 +54,7 @@ export function destroy_component(component, detaching) {
if (component.$$.fragment) {
run_all(component.$$.on_destroy);
if (detaching) component.$$.fragment.d(1);
component.$$.fragment.d(detaching);
// TODO null out other refs, including component.$$ (but need to
// preserve final state?)

@ -0,0 +1,15 @@
<script>
import { onDestroy } from 'svelte';
import { destroyed } from './destroyed.js';
import B from './B.svelte';
let yes = 1;
onDestroy(() => destroyed.push('A'));
</script>
<div>
{#if yes}
<B/>
{/if}
</div>

@ -0,0 +1,15 @@
<script>
import { onDestroy } from 'svelte';
import { destroyed } from './destroyed.js';
import C from './C.svelte';
let yes = 1;
onDestroy(() => destroyed.push('B'));
</script>
<div>
{#if yes}
<C/>
{/if}
</div>

@ -0,0 +1,8 @@
<script>
import { onDestroy } from 'svelte';
import { destroyed } from './destroyed.js';
let yes = 1;
onDestroy(() => destroyed.push('C'));
</script>

@ -0,0 +1,10 @@
import { destroyed, reset } from './destroyed.js';
export default {
test({ assert, component }) {
component.visible = false;
assert.deepEqual(destroyed, ['A', 'B', 'C']);
reset();
}
};

@ -0,0 +1,3 @@
export const destroyed = [];
export const reset = () => destroyed.length = 0;

@ -0,0 +1,9 @@
<script>
import A from './A.svelte';
export let visible = true;
</script>
{#if visible}
<A/>
{/if}
Loading…
Cancel
Save