fix some stuff

blockless
Rich Harris 2 years ago
parent 26e9c8ca18
commit 7190f991e7

@ -11,6 +11,7 @@ export const MAYBE_DIRTY = 1 << 10;
export const INERT = 1 << 11; export const INERT = 1 << 11;
export const DESTROYED = 1 << 12; export const DESTROYED = 1 << 12;
export const ROOT_EFFECT = 1 << 13; export const ROOT_EFFECT = 1 << 13;
export const BRANCH_EFFECT = 1 << 14;
export const ROOT_BLOCK = 0; export const ROOT_BLOCK = 0;
export const IF_BLOCK = 1; export const IF_BLOCK = 1;

@ -33,7 +33,7 @@ import {
import { source, mutable_source } from '../../reactivity/sources.js'; import { source, mutable_source } from '../../reactivity/sources.js';
import { trigger_transitions } from '../../transitions.js'; import { trigger_transitions } from '../../transitions.js';
import { is_array } from '../../utils.js'; import { is_array } from '../../utils.js';
import { EACH_BLOCK, EACH_ITEM_BLOCK } from '../../constants.js'; import { BRANCH_EFFECT, EACH_BLOCK, EACH_ITEM_BLOCK } from '../../constants.js';
import { unstate } from '../../proxy.js'; import { unstate } from '../../proxy.js';
const NEW_BLOCK = -1; const NEW_BLOCK = -1;
@ -462,7 +462,7 @@ export function each_indexed(anchor_node, collection, flags, render_fn, fallback
} }
length = nl; length = nl;
}); }).f |= BRANCH_EFFECT; // TODO create a primitive for this
} }
/** /**

@ -7,6 +7,7 @@ import {
import { remove } from '../../reconciler.js'; import { remove } from '../../reconciler.js';
import { pause_effect, render_effect, resume_effect } from '../../reactivity/computations.js'; import { pause_effect, render_effect, resume_effect } from '../../reactivity/computations.js';
import { current_effect } from '../../runtime.js'; import { current_effect } from '../../runtime.js';
import { BRANCH_EFFECT, RENDER_EFFECT } from '../../constants.js';
/** /**
* @param {Comment} anchor_node * @param {Comment} anchor_node
@ -76,5 +77,5 @@ export function if_block(anchor_node, condition_fn, consequent_fn, alternate_fn)
}); });
} }
} }
}); }).f |= BRANCH_EFFECT; // TODO create a primitive for this
} }

@ -314,9 +314,12 @@ function pause_children(effect, transitions) {
export function destroy_effect(effect) { export function destroy_effect(effect) {
// TODO call cleanup functions (but not sure when exactly?) // TODO call cleanup functions (but not sure when exactly?)
// TODO detach from parent effect
// TODO distinguish between 'block effects' (?) which own their own DOM // TODO distinguish between 'block effects' (?) which own their own DOM
// and other render effects // and other render effects
if (effect.dom) { if (effect.dom) {
// TODO skip already-detached DOM
remove(effect.dom); remove(effect.dom);
} }

@ -27,7 +27,8 @@ import {
INERT, INERT,
MANAGED, MANAGED,
SOURCE, SOURCE,
STATE_SYMBOL STATE_SYMBOL,
BRANCH_EFFECT
} from './constants.js'; } from './constants.js';
import { flush_tasks } from './dom/task.js'; import { flush_tasks } from './dom/task.js';
@ -404,7 +405,12 @@ export function execute_effect(signal) {
current_effect = signal; current_effect = signal;
try { try {
destroy_references(signal); if ((signal.f & BRANCH_EFFECT) === 0) {
// branch effects (i.e. {#if ...} blocks) need to keep their references
// TODO their children should detach themselves from signal.r when destroyed
destroy_references(signal);
}
if (teardown !== null) { if (teardown !== null) {
teardown(); teardown();
} }

Loading…
Cancel
Save