chore: simplify process_effects (#15270)

* chore: simplify process_effects

* return effects
pull/15274/head
Rich Harris 7 months ago committed by GitHub
parent 280d8c74cc
commit 73220b8667
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -679,10 +679,7 @@ function flush_queued_root_effects(root_effects) {
effect.f ^= CLEAN; effect.f ^= CLEAN;
} }
/** @type {Effect[]} */ var collected_effects = process_effects(effect);
var collected_effects = [];
process_effects(effect, collected_effects);
flush_queued_effects(collected_effects); flush_queued_effects(collected_effects);
} }
} finally { } finally {
@ -783,13 +780,14 @@ export function schedule_effect(signal) {
* effects to be flushed. * effects to be flushed.
* *
* @param {Effect} effect * @param {Effect} effect
* @param {Effect[]} collected_effects * @returns {Effect[]}
* @returns {void}
*/ */
function process_effects(effect, collected_effects) { function process_effects(effect) {
var current_effect = effect.first; /** @type {Effect[]} */
var effects = []; var effects = [];
var current_effect = effect.first;
main_loop: while (current_effect !== null) { main_loop: while (current_effect !== null) {
var flags = current_effect.f; var flags = current_effect.f;
var is_branch = (flags & BRANCH_EFFECT) !== 0; var is_branch = (flags & BRANCH_EFFECT) !== 0;
@ -797,34 +795,32 @@ function process_effects(effect, collected_effects) {
var sibling = current_effect.next; var sibling = current_effect.next;
if (!is_skippable_branch && (flags & INERT) === 0) { if (!is_skippable_branch && (flags & INERT) === 0) {
if ((flags & RENDER_EFFECT) !== 0) { if ((flags & EFFECT) !== 0) {
if (is_branch) { effects.push(current_effect);
current_effect.f ^= CLEAN; } else if (is_branch) {
} else { current_effect.f ^= CLEAN;
// Ensure we set the effect to be the active reaction } else {
// to ensure that unowned deriveds are correctly tracked // Ensure we set the effect to be the active reaction
// because we're flushing the current effect // to ensure that unowned deriveds are correctly tracked
var previous_active_reaction = active_reaction; // because we're flushing the current effect
try { var previous_active_reaction = active_reaction;
active_reaction = current_effect; try {
if (check_dirtiness(current_effect)) { active_reaction = current_effect;
update_effect(current_effect); if (check_dirtiness(current_effect)) {
} update_effect(current_effect);
} catch (error) {
handle_error(error, current_effect, null, current_effect.ctx);
} finally {
active_reaction = previous_active_reaction;
} }
} catch (error) {
handle_error(error, current_effect, null, current_effect.ctx);
} finally {
active_reaction = previous_active_reaction;
} }
}
var child = current_effect.first; var child = current_effect.first;
if (child !== null) { if (child !== null) {
current_effect = child; current_effect = child;
continue; continue;
}
} else if ((flags & EFFECT) !== 0) {
effects.push(current_effect);
} }
} }
@ -847,13 +843,7 @@ function process_effects(effect, collected_effects) {
current_effect = sibling; current_effect = sibling;
} }
// We might be dealing with many effects here, far more than can be spread into return effects;
// an array push call (callstack overflow). So let's deal with each effect in a loop.
for (var i = 0; i < effects.length; i++) {
child = effects[i];
collected_effects.push(child);
process_effects(child, collected_effects);
}
} }
/** /**

Loading…
Cancel
Save