use $state.eager mechanism for $effect.pending - way simpler and more robust

pull/17038/head
Rich Harris 3 weeks ago
parent 01d7853606
commit 584a52d2b5

@ -80,7 +80,7 @@ export function CallExpression(node, context) {
);
case '$effect.pending':
return b.call('$.pending');
return b.call('$.eager', b.thunk(b.call('$.pending')));
case '$inspect':
case '$inspect().with':

@ -34,7 +34,7 @@ import { queue_micro_task } from '../task.js';
import * as e from '../../errors.js';
import * as w from '../../warnings.js';
import { DEV } from 'esm-env';
import { Batch, effect_pending_updates } from '../../reactivity/batch.js';
import { Batch } 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';
@ -110,12 +110,6 @@ export class Boundary {
*/
#effect_pending = null;
#effect_pending_update = () => {
if (this.#effect_pending) {
internal_set(this.#effect_pending, this.#local_pending_count);
}
};
#effect_pending_subscriber = createSubscriber(() => {
this.#effect_pending = source(this.#local_pending_count);
@ -329,7 +323,10 @@ export class Boundary {
this.#update_pending_count(d);
this.#local_pending_count += d;
effect_pending_updates.add(this.#effect_pending_update);
if (this.#effect_pending) {
internal_set(this.#effect_pending, this.#local_pending_count);
}
}
get_effect_pending() {

@ -74,9 +74,6 @@ export let previous_batch = null;
*/
export let batch_values = null;
/** @type {Set<() => void>} */
export let effect_pending_updates = new Set();
/** @type {Effect[]} */
let queued_root_effects = [];
@ -324,16 +321,6 @@ export class Batch {
}
this.deactivate();
for (const update of effect_pending_updates) {
effect_pending_updates.delete(update);
update();
if (current_batch !== null) {
// only do one at a time
break;
}
}
}
discard() {

Loading…
Cancel
Save