custom element call onDestroy when disconnected

pull/4522/head
hontas 7 years ago
parent 9e78f39212
commit 18334b4477

@ -184,6 +184,10 @@ if (typeof HTMLElement === 'function') {
this[attr] = newValue;
}
disconnectedCallback() {
this.$destroy();
}
$destroy() {
destroy_component(this, 1);
this.$destroy = noop;

@ -0,0 +1,22 @@
<svelte:options tag="my-app"/>
<script>
import { onMount, onDestroy } from 'svelte';
let el;
let parentEl;
onMount(() => {
parentEl = el.parentNode.host.parentElement;
return () => {
parentEl.dataset.onMountDestroyed = true;
}
});
onDestroy(() => {
parentEl.dataset.destroyed = true;
})
</script>
<div bind:this={el}></div>

@ -0,0 +1,11 @@
import * as assert from 'assert';
import './main.svelte';
export default function (target) {
target.innerHTML = '<my-app/>';
const el = target.querySelector('my-app');
target.removeChild(el);
assert.ok(target.dataset.onMountDestroyed);
assert.ok(target.dataset.destroyed);
}
Loading…
Cancel
Save