pull/12073/head
Rich Harris 5 months ago
parent f6302d1b6b
commit 5b11c396f2

@ -103,7 +103,7 @@ export function update_derived(derived) {
*/ */
export function destroy_derived(signal) { export function destroy_derived(signal) {
destroy_derived_children(signal); destroy_derived_children(signal);
remove_reactions(signal, 0); remove_reactions(signal);
set_signal_status(signal, DESTROYED); set_signal_status(signal, DESTROYED);
// TODO we need to ensure we remove the derived from any parent derives // TODO we need to ensure we remove the derived from any parent derives

@ -343,7 +343,7 @@ export function destroy_effect(effect, remove_dom = true) {
} }
destroy_effect_children(effect, remove_dom); destroy_effect_children(effect, remove_dom);
remove_reactions(effect, 0); remove_reactions(effect);
set_signal_status(effect, DESTROYED); set_signal_status(effect, DESTROYED);
if (effect.transitions) { if (effect.transitions) {

@ -336,33 +336,28 @@ function remove_reaction(signal, dependency) {
} }
} }
} }
// If the derived has no reactions, then we can disconnect it from the graph, // If the derived has no reactions, then we can disconnect it from the graph,
// allowing it to either reconnect in the future, or be GC'd by the VM. // allowing it to either reconnect in the future, or be GC'd by the VM.
if (reactions_length === 0 && (dependency.f & DERIVED) !== 0) { if (reactions_length === 0 && (dependency.f & DERIVED) !== 0) {
set_signal_status(dependency, MAYBE_DIRTY); set_signal_status(dependency, MAYBE_DIRTY);
remove_reactions(/** @type {import('#client').Derived} **/ (dependency), 0); remove_reactions(/** @type {import('#client').Derived} **/ (dependency));
} }
} }
/** /**
* @param {import('#client').Reaction} signal * @param {import('#client').Reaction} signal
* @param {number} start_index
* @returns {void} * @returns {void}
*/ */
export function remove_reactions(signal, start_index) { export function remove_reactions(signal) {
const dependencies = signal.deps; var dependencies = signal.deps;
if (dependencies !== null) { if (dependencies === null) return;
const active_dependencies = start_index === 0 ? null : dependencies.slice(0, start_index);
let i; for (var i = 0; i < dependencies.length; i++) {
for (i = start_index; i < dependencies.length; i++) { var dependency = dependencies[i];
const dependency = dependencies[i];
// Avoid removing a reaction if we know that it is active (start_index will not be 0)
if (active_dependencies === null || !active_dependencies.includes(dependency)) {
remove_reaction(signal, dependency); remove_reaction(signal, dependency);
} }
} }
}
}
/** /**
* @param {import('#client').Reaction} signal * @param {import('#client').Reaction} signal

Loading…
Cancel
Save