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

@ -103,7 +103,7 @@ export function update_derived(derived) {
*/
export function destroy_derived(signal) {
destroy_derived_children(signal);
remove_reactions(signal, 0);
remove_reactions(signal);
set_signal_status(signal, DESTROYED);
// 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);
remove_reactions(effect, 0);
remove_reactions(effect);
set_signal_status(effect, DESTROYED);
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,
// allowing it to either reconnect in the future, or be GC'd by the VM.
if (reactions_length === 0 && (dependency.f & DERIVED) !== 0) {
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 {number} start_index
* @returns {void}
*/
export function remove_reactions(signal, start_index) {
const dependencies = signal.deps;
if (dependencies !== null) {
const active_dependencies = start_index === 0 ? null : dependencies.slice(0, start_index);
let i;
for (i = start_index; i < dependencies.length; 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)) {
export function remove_reactions(signal) {
var dependencies = signal.deps;
if (dependencies === null) return;
for (var i = 0; i < dependencies.length; i++) {
var dependency = dependencies[i];
remove_reaction(signal, dependency);
}
}
}
}
/**
* @param {import('#client').Reaction} signal

Loading…
Cancel
Save