diff --git a/packages/svelte/src/internal/client/reactivity/batch.js b/packages/svelte/src/internal/client/reactivity/batch.js index e22790b8dc..6875e2cd4e 100644 --- a/packages/svelte/src/internal/client/reactivity/batch.js +++ b/packages/svelte/src/internal/client/reactivity/batch.js @@ -23,13 +23,13 @@ function update_pending() { let uid = 1; export class Batch { - id = uid++; + #id = uid++; /** @type {Map} */ - previous = new Map(); + #previous = new Map(); /** @type {Map} */ - current = new Map(); + #current = new Map(); /** @type {Set} */ skipped_effects = new Set(); @@ -37,7 +37,7 @@ export class Batch { /** @type {Set<() => void>} */ #callbacks = new Set(); - pending = 0; + #pending = 0; apply() { // common case: no overlapping batches, nothing to revert @@ -45,7 +45,7 @@ export class Batch { var current_values = new Map(); - for (const [source, current] of this.current) { + for (const [source, current] of this.#current) { // TODO this shouldn't be necessary, but tests fail otherwise, // presumably because we need a try-finally somewhere, and the // source wasn't correctly reverted after the previous batch @@ -55,8 +55,8 @@ export class Batch { for (const batch of batches) { if (batch === this) continue; - for (const [source, previous] of batch.previous) { - if (!this.previous.has(source)) { + for (const [source, previous] of batch.#previous) { + if (!this.#previous.has(source)) { // mark_reactions(source, DIRTY); current_values.set(source, source.v); source.v = previous; @@ -76,27 +76,27 @@ export class Batch { * @param {any} value */ capture(source, value) { - if (!this.previous.has(source)) { - this.previous.set(source, value); + if (!this.#previous.has(source)) { + this.#previous.set(source, value); } - this.current.set(source, source.v); + this.#current.set(source, source.v); } remove() { batches.delete(this); for (var batch of batches) { - if (batch.id < this.id) { + if (batch.#id < this.#id) { // other batch is older than this - for (var source of this.previous.keys()) { - batch.previous.delete(source); + for (var source of this.#previous.keys()) { + batch.#previous.delete(source); } } else { // other batch is newer than this - for (var source of batch.previous.keys()) { - if (this.previous.has(source)) { - batch.previous.set(source, source.v); + for (var source of batch.#previous.keys()) { + if (this.#previous.has(source)) { + batch.#previous.set(source, source.v); } } } @@ -114,15 +114,15 @@ export class Batch { } increment() { - this.pending += 1; + this.#pending += 1; } decrement() { - this.pending -= 1; + this.#pending -= 1; } settled() { - return this.pending === 0; + return this.#pending === 0; } /** @param {() => void} fn */ diff --git a/packages/svelte/src/internal/client/runtime.js b/packages/svelte/src/internal/client/runtime.js index 10ec5c536d..62ba5d041d 100644 --- a/packages/svelte/src/internal/client/runtime.js +++ b/packages/svelte/src/internal/client/runtime.js @@ -720,7 +720,7 @@ function flush_queued_root_effects() { process_effects(root, async_effects, render_effects, effects); } - if (async_effects.length === 0 && batch.pending === 0) { + if (async_effects.length === 0 && batch.settled()) { batch.commit(); flush_queued_effects(render_effects); flush_queued_effects(effects); @@ -798,7 +798,7 @@ export function schedule_effect(signal) { flush_queued_root_effects(); - if (current_batch?.pending === 0) { + if (current_batch?.settled()) { current_batch.remove(); } @@ -920,7 +920,7 @@ export function flushSync(fn) { flush_tasks(); } - if (current_batch?.pending === 0) { + if (current_batch?.settled()) { current_batch.remove(); }