|
|
|
|
@ -7,9 +7,11 @@ import {
|
|
|
|
|
destroy_effect_children,
|
|
|
|
|
execute_effect,
|
|
|
|
|
get,
|
|
|
|
|
is_destroying_effect,
|
|
|
|
|
is_flushing_effect,
|
|
|
|
|
remove_reactions,
|
|
|
|
|
schedule_effect,
|
|
|
|
|
set_is_destroying_effect,
|
|
|
|
|
set_is_flushing_effect,
|
|
|
|
|
set_signal_status,
|
|
|
|
|
untrack
|
|
|
|
|
@ -24,7 +26,7 @@ import {
|
|
|
|
|
EFFECT_RAN,
|
|
|
|
|
BLOCK_EFFECT,
|
|
|
|
|
ROOT_EFFECT,
|
|
|
|
|
IS_ELSEIF
|
|
|
|
|
EFFECT_TRANSPARENT
|
|
|
|
|
} from '../constants.js';
|
|
|
|
|
import { set } from './sources.js';
|
|
|
|
|
import { remove } from '../dom/reconciler.js';
|
|
|
|
|
@ -109,6 +111,12 @@ export function user_effect(fn) {
|
|
|
|
|
(DEV ? ': The Svelte $effect rune can only be used during component initialisation.' : '')
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (is_destroying_effect) {
|
|
|
|
|
throw new Error(
|
|
|
|
|
'ERR_SVELTE_EFFECT_IN_TEARDOWN' +
|
|
|
|
|
(DEV ? ': The Svelte $effect rune can not be used in the teardown phase of an effect.' : '')
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Non-nested `$effect(...)` in a component should be deferred
|
|
|
|
|
// until the component is mounted
|
|
|
|
|
@ -140,6 +148,14 @@ export function user_pre_effect(fn) {
|
|
|
|
|
: '')
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (is_destroying_effect) {
|
|
|
|
|
throw new Error(
|
|
|
|
|
'ERR_SVELTE_EFFECT_IN_TEARDOWN' +
|
|
|
|
|
(DEV
|
|
|
|
|
? ': The Svelte $effect.pre rune can not be used in the teardown phase of an effect.'
|
|
|
|
|
: '')
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return render_effect(fn);
|
|
|
|
|
}
|
|
|
|
|
@ -228,6 +244,22 @@ export function branch(fn) {
|
|
|
|
|
return create_effect(RENDER_EFFECT | BRANCH_EFFECT, fn, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param {import("#client").Effect} effect
|
|
|
|
|
*/
|
|
|
|
|
export function execute_effect_teardown(effect) {
|
|
|
|
|
var teardown = effect.teardown;
|
|
|
|
|
if (teardown !== null) {
|
|
|
|
|
const previously_destroying_effect = is_destroying_effect;
|
|
|
|
|
set_is_destroying_effect(true);
|
|
|
|
|
try {
|
|
|
|
|
teardown.call(null);
|
|
|
|
|
} finally {
|
|
|
|
|
set_is_destroying_effect(previously_destroying_effect);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param {import('#client').Effect} effect
|
|
|
|
|
* @returns {void}
|
|
|
|
|
@ -249,7 +281,7 @@ export function destroy_effect(effect) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
effect.teardown?.call(null);
|
|
|
|
|
execute_effect_teardown(effect);
|
|
|
|
|
|
|
|
|
|
var parent = effect.parent;
|
|
|
|
|
|
|
|
|
|
@ -345,7 +377,7 @@ export function pause_children(effect, transitions, local) {
|
|
|
|
|
|
|
|
|
|
while (child !== null) {
|
|
|
|
|
var sibling = child.next;
|
|
|
|
|
var transparent = (child.f & IS_ELSEIF) !== 0 || (child.f & BRANCH_EFFECT) !== 0;
|
|
|
|
|
var transparent = (child.f & EFFECT_TRANSPARENT) !== 0 || (child.f & BRANCH_EFFECT) !== 0;
|
|
|
|
|
// TODO we don't need to call pause_children recursively with a linked list in place
|
|
|
|
|
// it's slightly more involved though as we have to account for `transparent` changing
|
|
|
|
|
// through the tree.
|
|
|
|
|
@ -381,7 +413,7 @@ function resume_children(effect, local) {
|
|
|
|
|
|
|
|
|
|
while (child !== null) {
|
|
|
|
|
var sibling = child.next;
|
|
|
|
|
var transparent = (child.f & IS_ELSEIF) !== 0 || (child.f & BRANCH_EFFECT) !== 0;
|
|
|
|
|
var transparent = (child.f & EFFECT_TRANSPARENT) !== 0 || (child.f & BRANCH_EFFECT) !== 0;
|
|
|
|
|
// TODO we don't need to call resume_children recursively with a linked list in place
|
|
|
|
|
// it's slightly more involved though as we have to account for `transparent` changing
|
|
|
|
|
// through the tree.
|
|
|
|
|
|