during traversal, add effects directly to flush queue rather than scheduling them

refactor-scheduling
Rich Harris 2 days ago
parent 9c1127ed11
commit fafa495b58

@ -69,6 +69,9 @@ let last_scheduled_effect = null;
let is_flushing = false;
export let is_flushing_sync = false;
/** @type {Effect[] | null} */
export let current_effects = null;
export class Batch {
/**
* The current values of any sources that are updated in this batch
@ -185,7 +188,7 @@ export class Batch {
this.apply();
/** @type {Effect[]} */
var effects = [];
var effects = (current_effects = []);
/** @type {Effect[]} */
var render_effects = [];
@ -199,6 +202,8 @@ export class Batch {
// log_inconsistent_branches(root);
}
current_effects = null;
if (this.#is_deferred()) {
this.#defer_effects(render_effects);
this.#defer_effects(effects);

@ -40,7 +40,7 @@ import { DEV } from 'esm-env';
import { define_property } from '../../shared/utils.js';
import { get_next_sibling } from '../dom/operations.js';
import { component_context, dev_current_component_function, dev_stack } from '../context.js';
import { Batch, schedule_effect } from './batch.js';
import { Batch, current_effects, schedule_effect } from './batch.js';
import { flatten, increment_pending } from './async.js';
import { without_reactive_context } from '../dom/elements/bindings/shared.js';
import { set_signal_status } from './status.js';
@ -127,8 +127,12 @@ function create_effect(type, fn, sync) {
throw e;
}
} else if (fn !== null) {
Batch.ensure();
schedule_effect(effect);
if (current_effects !== null) {
current_effects.push(effect);
} else {
Batch.ensure();
schedule_effect(effect);
}
}
/** @type {Effect | null} */

Loading…
Cancel
Save