Skip to content

Commit bf9e109

Browse files
committed
make flush_queued_root_effects a method of batch
1 parent ec21b74 commit bf9e109

File tree

1 file changed

+31
-32
lines changed
  • packages/svelte/src/internal/client/reactivity

1 file changed

+31
-32
lines changed

packages/svelte/src/internal/client/reactivity/batch.js

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,13 @@ export class Batch {
256256

257257
flush() {
258258
if (queued_root_effects.length > 0) {
259-
flush_queued_root_effects();
259+
this.flush_effects();
260260
} else {
261261
this.#commit();
262262
}
263263

264264
if (current_batch !== this) {
265-
// this can happen if a `flushSync` occurred during `flush_queued_root_effects`,
265+
// this can happen if a `flushSync` occurred during `this.flush_effects()`,
266266
// which is permitted in legacy mode despite being a terrible idea
267267
return;
268268
}
@@ -274,6 +274,32 @@ export class Batch {
274274
current_batch = null;
275275
}
276276

277+
flush_effects() {
278+
var was_updating_effect = is_updating_effect;
279+
280+
try {
281+
var flush_count = 0;
282+
set_is_updating_effect(true);
283+
284+
while (queued_root_effects.length > 0) {
285+
if (flush_count++ > 1000) {
286+
infinite_loop_guard();
287+
}
288+
289+
this.process(queued_root_effects);
290+
291+
old_values.clear();
292+
}
293+
} finally {
294+
set_is_updating_effect(was_updating_effect);
295+
296+
last_scheduled_effect = null;
297+
if (DEV) {
298+
dev_effect_stack.length = 0;
299+
}
300+
}
301+
}
302+
277303
#commit() {
278304
for (const fn of this.#callbacks) {
279305
fn();
@@ -368,7 +394,7 @@ export function flushSync(fn) {
368394
const batch = Batch.ensure();
369395

370396
if (fn) {
371-
flush_queued_root_effects();
397+
batch.flush_effects();
372398

373399
result = fn();
374400
}
@@ -381,7 +407,7 @@ export function flushSync(fn) {
381407
batch.flush();
382408
}
383409

384-
// this would be reset in `flush_queued_root_effects` but since we are early returning here,
410+
// this would be reset in `batch.flush_effects()` but since we are early returning here,
385411
// we need to reset it here as well in case the first time there's 0 queued root effects
386412
last_scheduled_effect = null;
387413

@@ -392,7 +418,7 @@ export function flushSync(fn) {
392418
return /** @type {T} */ (result);
393419
}
394420

395-
flush_queued_root_effects();
421+
batch.flush_effects();
396422
}
397423
}
398424

@@ -438,33 +464,6 @@ function infinite_loop_guard() {
438464
}
439465
}
440466

441-
export function flush_queued_root_effects() {
442-
var was_updating_effect = is_updating_effect;
443-
var batch = /** @type {Batch} */ (current_batch);
444-
445-
try {
446-
var flush_count = 0;
447-
set_is_updating_effect(true);
448-
449-
while (queued_root_effects.length > 0) {
450-
if (flush_count++ > 1000) {
451-
infinite_loop_guard();
452-
}
453-
454-
batch.process(queued_root_effects);
455-
456-
old_values.clear();
457-
}
458-
} finally {
459-
set_is_updating_effect(was_updating_effect);
460-
461-
last_scheduled_effect = null;
462-
if (DEV) {
463-
dev_effect_stack.length = 0;
464-
}
465-
}
466-
}
467-
468467
/**
469468
* @param {Array<Effect>} effects
470469
* @returns {void}

0 commit comments

Comments
 (0)