Batch Class — svelte Architecture
Architecture documentation for the Batch class in batch.js from the svelte codebase.
Entity Profile
Dependency Diagram
graph TD 517c145b_769f_b163_6854_d8f2a4412e11["Batch"] d8e42d9d_2e3c_635c_19d3_b946a4341c0f["batch.js"] 517c145b_769f_b163_6854_d8f2a4412e11 -->|defined in| d8e42d9d_2e3c_635c_19d3_b946a4341c0f 4774c826_f54f_963c_c1ab_fc51e1b4c790["is_deferred()"] 517c145b_769f_b163_6854_d8f2a4412e11 -->|method| 4774c826_f54f_963c_c1ab_fc51e1b4c790 5d586c82_3240_946e_57e6_6b7c46e8825e["skip_effect()"] 517c145b_769f_b163_6854_d8f2a4412e11 -->|method| 5d586c82_3240_946e_57e6_6b7c46e8825e 4884c8a4_7cc6_1b32_b689_ac96e3d81e91["unskip_effect()"] 517c145b_769f_b163_6854_d8f2a4412e11 -->|method| 4884c8a4_7cc6_1b32_b689_ac96e3d81e91 05511be0_1e56_3876_59e2_7350fc912bb9["process()"] 517c145b_769f_b163_6854_d8f2a4412e11 -->|method| 05511be0_1e56_3876_59e2_7350fc912bb9 c19ea0c4_0909_9915_ac53_f65d5af69919["root()"] 517c145b_769f_b163_6854_d8f2a4412e11 -->|method| c19ea0c4_0909_9915_ac53_f65d5af69919 9ff5deaa_0417_faaf_da92_5b566dc2b490["effects()"] 517c145b_769f_b163_6854_d8f2a4412e11 -->|method| 9ff5deaa_0417_faaf_da92_5b566dc2b490 c6834881_4d11_32ef_6bfe_2be0c88e456b["capture()"] 517c145b_769f_b163_6854_d8f2a4412e11 -->|method| c6834881_4d11_32ef_6bfe_2be0c88e456b e2994140_cbea_e6ee_c66f_0adec4e39cd7["activate()"] 517c145b_769f_b163_6854_d8f2a4412e11 -->|method| e2994140_cbea_e6ee_c66f_0adec4e39cd7 a0b8f840_863f_a966_d259_b866f80703d1["deactivate()"] 517c145b_769f_b163_6854_d8f2a4412e11 -->|method| a0b8f840_863f_a966_d259_b866f80703d1 ec59c019_2fd3_2a1c_3cf5_7cd95b795a96["flush()"] 517c145b_769f_b163_6854_d8f2a4412e11 -->|method| ec59c019_2fd3_2a1c_3cf5_7cd95b795a96 3a656fc9_97e1_c1e1_53aa_c39cb7503b64["discard()"] 517c145b_769f_b163_6854_d8f2a4412e11 -->|method| 3a656fc9_97e1_c1e1_53aa_c39cb7503b64 dd2db25f_ec55_d3be_61b9_c180c4e4cbc8["batches()"] 517c145b_769f_b163_6854_d8f2a4412e11 -->|method| dd2db25f_ec55_d3be_61b9_c180c4e4cbc8 ab9c13ec_1c6d_0b81_72f5_188dfda4191b["increment()"] 517c145b_769f_b163_6854_d8f2a4412e11 -->|method| ab9c13ec_1c6d_0b81_72f5_188dfda4191b
Relationship Graph
Source Code
packages/svelte/src/internal/client/reactivity/batch.js lines 73–554
export class Batch {
committed = false;
/**
* The current values of any sources that are updated in this batch
* They keys of this map are identical to `this.#previous`
* @type {Map<Source, any>}
*/
current = new Map();
/**
* The values of any sources that are updated in this batch _before_ those updates took place.
* They keys of this map are identical to `this.#current`
* @type {Map<Source, any>}
*/
previous = new Map();
/**
* When the batch is committed (and the DOM is updated), we need to remove old branches
* and append new ones by calling the functions added inside (if/each/key/etc) blocks
* @type {Set<() => void>}
*/
#commit_callbacks = new Set();
/**
* If a fork is discarded, we need to destroy any effects that are no longer needed
* @type {Set<(batch: Batch) => void>}
*/
#discard_callbacks = new Set();
/**
* The number of async effects that are currently in flight
*/
#pending = 0;
/**
* The number of async effects that are currently in flight, _not_ inside a pending boundary
*/
#blocking_pending = 0;
/**
* A deferred that resolves when the batch is committed, used with `settled()`
* TODO replace with Promise.withResolvers once supported widely enough
* @type {{ promise: Promise<void>, resolve: (value?: any) => void, reject: (reason: unknown) => void } | null}
*/
#deferred = null;
/**
* Deferred effects (which run after async work has completed) that are DIRTY
* @type {Set<Effect>}
*/
#dirty_effects = new Set();
/**
* Deferred effects that are MAYBE_DIRTY
* @type {Set<Effect>}
*/
#maybe_dirty_effects = new Set();
/**
* A map of branches that still exist, but will be destroyed when this batch
* is committed — we skip over these during `process`.
* The value contains child effects that were dirty/maybe_dirty before being reset,
* so they can be rescheduled if the branch survives.
* @type {Map<Effect, { d: Effect[], m: Effect[] }>}
*/
#skipped_branches = new Map();
is_fork = false;
#decrement_queued = false;
is_deferred() {
return this.is_fork || this.#blocking_pending > 0;
}
/**
* Add an effect to the #skipped_branches map and reset its children
* @param {Effect} effect
*/
skip_effect(effect) {
Domain
Source
Frequently Asked Questions
What is the Batch class?
Batch is a class in the svelte codebase, defined in packages/svelte/src/internal/client/reactivity/batch.js.
Where is Batch defined?
Batch is defined in packages/svelte/src/internal/client/reactivity/batch.js at line 73.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free