pull/16197/head
Rich Harris 5 months ago
parent 9e0bd4f24b
commit 0bc6e6977e

@ -1,6 +1,6 @@
/** @import { Effect, Source } from '#client' */ /** @import { Effect, Source } from '#client' */
import { DIRTY } from '#client/constants'; import { DIRTY } from '#client/constants';
import { schedule_effect, set_signal_status } from '../runtime.js'; import { schedule_effect, set_signal_status, update_effect } from '../runtime.js';
import { raf } from '../timing.js'; import { raf } from '../timing.js';
import { internal_set, mark_reactions, pending } from './sources.js'; import { internal_set, mark_reactions, pending } from './sources.js';
@ -35,6 +35,9 @@ export class Batch {
#pending = 0; #pending = 0;
/** @type {Effect[]} */
async_effects = [];
/** @type {Effect[]} */ /** @type {Effect[]} */
effects = []; effects = [];
@ -73,6 +76,12 @@ export class Batch {
for (const [source, value] of current_values) { for (const [source, value] of current_values) {
source.v = value; source.v = value;
} }
for (const effect of this.async_effects) {
update_effect(effect);
}
this.async_effects = [];
}; };
} }

@ -697,9 +697,6 @@ function flush_queued_root_effects() {
var revert = batch.apply(); var revert = batch.apply();
/** @type {Effect[]} */
var async_effects = [];
/** @type {Effect[]} */ /** @type {Effect[]} */
var render_effects = []; var render_effects = [];
@ -711,10 +708,10 @@ function flush_queued_root_effects() {
queued_root_effects = []; queued_root_effects = [];
for (const root of root_effects) { for (const root of root_effects) {
process_effects(batch, root, async_effects, render_effects, effects); process_effects(batch, root, render_effects, effects);
} }
if (async_effects.length === 0 && batch.settled()) { if (batch.async_effects.length === 0 && batch.settled()) {
batch.commit(); batch.commit();
flush_queued_effects(render_effects); flush_queued_effects(render_effects);
flush_queued_effects(effects); flush_queued_effects(effects);
@ -734,10 +731,6 @@ function flush_queued_root_effects() {
revert(); revert();
for (const effect of async_effects) {
update_effect(effect);
}
old_values.clear(); old_values.clear();
} }
} finally { } finally {
@ -836,11 +829,10 @@ export function schedule_effect(signal) {
* *
* @param {Batch} batch * @param {Batch} batch
* @param {Effect} root * @param {Effect} root
* @param {Effect[]} async_effects
* @param {Effect[]} render_effects * @param {Effect[]} render_effects
* @param {Effect[]} effects * @param {Effect[]} effects
*/ */
function process_effects(batch, root, async_effects, render_effects, effects) { function process_effects(batch, root, render_effects, effects) {
root.f ^= CLEAN; root.f ^= CLEAN;
var effect = root.first; var effect = root.first;
@ -855,7 +847,7 @@ function process_effects(batch, root, async_effects, render_effects, effects) {
if (!skip && effect.fn !== null) { if (!skip && effect.fn !== null) {
if ((flags & EFFECT_ASYNC) !== 0) { if ((flags & EFFECT_ASYNC) !== 0) {
if (check_dirtiness(effect)) { if (check_dirtiness(effect)) {
async_effects.push(effect); batch.async_effects.push(effect);
} }
} else if ((flags & BLOCK_EFFECT) !== 0) { } else if ((flags & BLOCK_EFFECT) !== 0) {
try { try {

Loading…
Cancel
Save