Skip to content

Commit 73220b8

Browse files
authored
chore: simplify process_effects (#15270)
* chore: simplify process_effects * return effects
1 parent 280d8c7 commit 73220b8

File tree

1 file changed

+29
-39
lines changed

1 file changed

+29
-39
lines changed

packages/svelte/src/internal/client/runtime.js

Lines changed: 29 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -679,10 +679,7 @@ function flush_queued_root_effects(root_effects) {
679679
effect.f ^= CLEAN;
680680
}
681681

682-
/** @type {Effect[]} */
683-
var collected_effects = [];
684-
685-
process_effects(effect, collected_effects);
682+
var collected_effects = process_effects(effect);
686683
flush_queued_effects(collected_effects);
687684
}
688685
} finally {
@@ -783,48 +780,47 @@ export function schedule_effect(signal) {
783780
* effects to be flushed.
784781
*
785782
* @param {Effect} effect
786-
* @param {Effect[]} collected_effects
787-
* @returns {void}
783+
* @returns {Effect[]}
788784
*/
789-
function process_effects(effect, collected_effects) {
790-
var current_effect = effect.first;
785+
function process_effects(effect) {
786+
/** @type {Effect[]} */
791787
var effects = [];
792788

789+
var current_effect = effect.first;
790+
793791
main_loop: while (current_effect !== null) {
794792
var flags = current_effect.f;
795793
var is_branch = (flags & BRANCH_EFFECT) !== 0;
796794
var is_skippable_branch = is_branch && (flags & CLEAN) !== 0;
797795
var sibling = current_effect.next;
798796

799797
if (!is_skippable_branch && (flags & INERT) === 0) {
800-
if ((flags & RENDER_EFFECT) !== 0) {
801-
if (is_branch) {
802-
current_effect.f ^= CLEAN;
803-
} else {
804-
// Ensure we set the effect to be the active reaction
805-
// to ensure that unowned deriveds are correctly tracked
806-
// because we're flushing the current effect
807-
var previous_active_reaction = active_reaction;
808-
try {
809-
active_reaction = current_effect;
810-
if (check_dirtiness(current_effect)) {
811-
update_effect(current_effect);
812-
}
813-
} catch (error) {
814-
handle_error(error, current_effect, null, current_effect.ctx);
815-
} finally {
816-
active_reaction = previous_active_reaction;
798+
if ((flags & EFFECT) !== 0) {
799+
effects.push(current_effect);
800+
} else if (is_branch) {
801+
current_effect.f ^= CLEAN;
802+
} else {
803+
// Ensure we set the effect to be the active reaction
804+
// to ensure that unowned deriveds are correctly tracked
805+
// because we're flushing the current effect
806+
var previous_active_reaction = active_reaction;
807+
try {
808+
active_reaction = current_effect;
809+
if (check_dirtiness(current_effect)) {
810+
update_effect(current_effect);
817811
}
812+
} catch (error) {
813+
handle_error(error, current_effect, null, current_effect.ctx);
814+
} finally {
815+
active_reaction = previous_active_reaction;
818816
}
817+
}
819818

820-
var child = current_effect.first;
819+
var child = current_effect.first;
821820

822-
if (child !== null) {
823-
current_effect = child;
824-
continue;
825-
}
826-
} else if ((flags & EFFECT) !== 0) {
827-
effects.push(current_effect);
821+
if (child !== null) {
822+
current_effect = child;
823+
continue;
828824
}
829825
}
830826

@@ -847,13 +843,7 @@ function process_effects(effect, collected_effects) {
847843
current_effect = sibling;
848844
}
849845

850-
// We might be dealing with many effects here, far more than can be spread into
851-
// an array push call (callstack overflow). So let's deal with each effect in a loop.
852-
for (var i = 0; i < effects.length; i++) {
853-
child = effects[i];
854-
collected_effects.push(child);
855-
process_effects(child, collected_effects);
856-
}
846+
return effects;
857847
}
858848

859849
/**

0 commit comments

Comments
 (0)