WIP sync effect pending updates

pull/16382/head
Rich Harris 2 months ago
parent 9f591223b1
commit 12160e0c33

@ -22,10 +22,11 @@ import { get_next_sibling } from '../operations.js';
import { queue_micro_task } from '../task.js';
import * as e from '../../errors.js';
import { DEV } from 'esm-env';
import { Batch } from '../../reactivity/batch.js';
import { Batch, effect_pending_updates } from '../../reactivity/batch.js';
import { internal_set, source } from '../../reactivity/sources.js';
import { tag } from '../../dev/tracing.js';
import { createSubscriber } from '../../../../reactivity/create-subscriber.js';
import { raf } from '../../timing.js';
/**
* @typedef {{
@ -92,6 +93,12 @@ export class Boundary {
*/
#effect_pending = null;
#effect_pending_update = () => {
if (this.#effect_pending) {
internal_set(this.#effect_pending, this.#pending_count);
}
};
#effect_pending_subscriber = createSubscriber(() => {
this.#effect_pending = source(this.#pending_count);
@ -238,11 +245,7 @@ export class Boundary {
this.parent.#update_pending_count(d);
}
queueMicrotask(() => {
if (this.#effect_pending) {
internal_set(this.#effect_pending, this.#pending_count);
}
});
effect_pending_updates.add(this.#effect_pending_update);
}
get_effect_pending() {

@ -49,6 +49,9 @@ export let batch_deriveds = null;
/** @type {Effect[]} Stack of effects, dev only */
export let dev_effect_stack = [];
/** @type {Set<() => void>} */
export let effect_pending_updates = new Set();
/** @type {Effect[]} */
let queued_root_effects = [];
@ -320,6 +323,12 @@ export class Batch {
}
current_batch = null;
for (const update of effect_pending_updates) {
effect_pending_updates.delete(update);
update();
break;
}
}
flush_effects() {

Loading…
Cancel
Save