remove some stuff we dont need

pull/10880/head
Rich Harris 2 years ago
parent 54cec48338
commit ae23e2536f

@ -24,12 +24,6 @@ import {
export function if_block(anchor, get_condition, consequent_fn, alternate_fn, elseif = false) { export function if_block(anchor, get_condition, consequent_fn, alternate_fn, elseif = false) {
hydrate_block_anchor(anchor); hydrate_block_anchor(anchor);
/** @type {undefined | import('#client').Dom} */
let consequent_dom;
/** @type {undefined | import('#client').Dom} */
let alternate_dom;
/** @type {import('#client').Effect | null} */ /** @type {import('#client').Effect | null} */
let consequent_effect = null; let consequent_effect = null;
@ -68,48 +62,24 @@ export function if_block(anchor, get_condition, consequent_fn, alternate_fn, els
if (consequent_effect) { if (consequent_effect) {
resume_effect(consequent_effect); resume_effect(consequent_effect);
} else { } else {
consequent_effect = render_effect(() => { consequent_effect = render_effect(() => consequent_fn(anchor), true);
consequent_dom = consequent_fn(anchor);
return () => {
// TODO make this unnecessary by linking the dom to the effect,
// and removing automatically on teardown
if (consequent_dom !== undefined) {
remove(consequent_dom);
consequent_dom = undefined;
}
};
}, true);
} }
if (alternate_effect) { if (alternate_effect) {
pause_effect(alternate_effect, () => { pause_effect(alternate_effect, () => {
alternate_effect = null; alternate_effect = null;
if (alternate_dom) remove(alternate_dom);
}); });
} }
} else { } else {
if (alternate_effect) { if (alternate_effect) {
resume_effect(alternate_effect); resume_effect(alternate_effect);
} else if (alternate_fn) { } else if (alternate_fn) {
alternate_effect = render_effect(() => { alternate_effect = render_effect(() => alternate_fn(anchor), true);
alternate_dom = alternate_fn(anchor);
return () => {
// TODO make this unnecessary by linking the dom to the effect,
// and removing automatically on teardown
if (alternate_dom !== undefined) {
remove(alternate_dom);
alternate_dom = undefined;
}
};
}, true);
} }
if (consequent_effect) { if (consequent_effect) {
pause_effect(consequent_effect, () => { pause_effect(consequent_effect, () => {
consequent_effect = null; consequent_effect = null;
if (consequent_dom) remove(consequent_dom);
}); });
} }
} }
@ -125,16 +95,7 @@ export function if_block(anchor, get_condition, consequent_fn, alternate_fn, els
} }
if_effect.ondestroy = () => { if_effect.ondestroy = () => {
// TODO make this unnecessary by linking the dom to the effect, // TODO why is this not automatic? this should be children of `if_effect`
// and removing automatically on teardown
if (consequent_dom !== undefined) {
remove(consequent_dom);
}
if (alternate_dom !== undefined) {
remove(alternate_dom);
}
if (consequent_effect) { if (consequent_effect) {
destroy_effect(consequent_effect); destroy_effect(consequent_effect);
} }

@ -24,6 +24,7 @@ import {
} from '../constants.js'; } from '../constants.js';
import { set } from './sources.js'; import { set } from './sources.js';
import { noop } from '../../common.js'; import { noop } from '../../common.js';
import { remove } from '../dom/reconciler.js';
/** /**
* @param {import('./types.js').EffectType} type * @param {import('./types.js').EffectType} type
@ -241,6 +242,11 @@ export function destroy_effect(effect) {
} }
effect.teardown?.(); effect.teardown?.();
if (effect.dom !== null) {
remove(effect.dom);
}
effect.ondestroy?.(); effect.ondestroy?.();
// @ts-expect-error // @ts-expect-error

Loading…
Cancel
Save