From 76b8d52de22c20b7b2510fec12fdc8291a67863d Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 7 Jul 2025 21:10:55 -0400 Subject: [PATCH] add more JSDoc --- .../src/internal/client/reactivity/batch.js | 35 +++++++++++-------- .../svelte/src/internal/client/runtime.js | 8 ----- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/packages/svelte/src/internal/client/reactivity/batch.js b/packages/svelte/src/internal/client/reactivity/batch.js index c05b1c0d2b..5da776bdc7 100644 --- a/packages/svelte/src/internal/client/reactivity/batch.js +++ b/packages/svelte/src/internal/client/reactivity/batch.js @@ -20,9 +20,7 @@ import { check_dirtiness, dev_effect_stack, is_updating_effect, - queued_root_effects, set_is_updating_effect, - set_queued_root_effects, set_signal_status, update_effect, write_version @@ -40,9 +38,17 @@ const batches = new Set(); /** @type {Batch | null} */ export let current_batch = null; -/** @type {Map | null} */ +/** + * When time travelling, we re-evaluate deriveds based on the temporary + * values of their dependencies rather than their actual values, and cache + * the results in this map rather than on the deriveds themselves + * @type {Map | null} + */ export let batch_deriveds = null; +/** @type {Effect[]} */ +let queued_root_effects = []; + /** @type {Effect | null} */ let last_scheduled_effect = null; @@ -125,20 +131,15 @@ export class Batch { * @param {Effect[]} root_effects */ #process(root_effects) { - set_queued_root_effects([]); + queued_root_effects = []; /** @type {Map | null} */ var current_values = null; - var time_travelling = false; - for (const batch of batches) { - if (batch !== this) { - time_travelling = true; - break; - } - } - - if (time_travelling) { + // if there are multiple batches, we are 'time travelling' — + // we need to undo the changes belonging to any batch + // other than the current one + if (batches.size > 1) { current_values = new Map(); batch_deriveds = new Map(); @@ -253,6 +254,8 @@ export class Batch { } /** + * Traverse the effect tree, executing effects or stashing + * them for later execution as appropriate * @param {Effect} root */ #process_root(root) { @@ -314,6 +317,8 @@ export class Batch { } /** + * Associate a change to a given source with the current + * batch, noting its previous and current values * @param {Source} source * @param {any} value */ @@ -366,7 +371,6 @@ export class Batch { } this.#process(queued_root_effects); - old_values.clear(); } } finally { @@ -379,6 +383,9 @@ export class Batch { } } + /** + * Append and remove branches to/from the DOM + */ #commit() { for (const fn of this.#callbacks) { fn(); diff --git a/packages/svelte/src/internal/client/runtime.js b/packages/svelte/src/internal/client/runtime.js index 093d875d60..1f5621674f 100644 --- a/packages/svelte/src/internal/client/runtime.js +++ b/packages/svelte/src/internal/client/runtime.js @@ -61,14 +61,6 @@ export function set_is_destroying_effect(value) { is_destroying_effect = value; } -/** @type {Effect[]} */ -export let queued_root_effects = []; - -/** @param {Effect[]} v */ -export function set_queued_root_effects(v) { - queued_root_effects = v; -} - /** @type {Effect[]} Stack of effects, dev only */ export let dev_effect_stack = [];