Home / Function/ flush_effects() — svelte Function Reference

flush_effects() — svelte Function Reference

Architecture documentation for the flush_effects() function in batch.js from the svelte codebase.

Entity Profile

Dependency Diagram

graph TD
  f618e317_1a72_981e_22c2_44b823813de7["flush_effects()"]
  d8e42d9d_2e3c_635c_19d3_b946a4341c0f["batch.js"]
  f618e317_1a72_981e_22c2_44b823813de7 -->|defined in| d8e42d9d_2e3c_635c_19d3_b946a4341c0f
  ec59c019_2fd3_2a1c_3cf5_7cd95b795a96["flush()"]
  ec59c019_2fd3_2a1c_3cf5_7cd95b795a96 -->|calls| f618e317_1a72_981e_22c2_44b823813de7
  5bc3c950_96f7_e454_6cb7_65ffc2179811["flushSync()"]
  5bc3c950_96f7_e454_6cb7_65ffc2179811 -->|calls| f618e317_1a72_981e_22c2_44b823813de7
  2ec0d2fd_8bbc_b2ba_53ae_f2da02bb3ba5["ensure()"]
  f618e317_1a72_981e_22c2_44b823813de7 -->|calls| 2ec0d2fd_8bbc_b2ba_53ae_f2da02bb3ba5
  a08b6cc5_af73_1be4_d02f_3113cf8a8305["get()"]
  f618e317_1a72_981e_22c2_44b823813de7 -->|calls| a08b6cc5_af73_1be4_d02f_3113cf8a8305
  63ee8247_ada4_9f1d_e139_0c1167cd5b1c["set()"]
  f618e317_1a72_981e_22c2_44b823813de7 -->|calls| 63ee8247_ada4_9f1d_e139_0c1167cd5b1c
  431e2e3a_6c7a_74a1_c2ad_9e368d12f115["infinite_loop_guard()"]
  f618e317_1a72_981e_22c2_44b823813de7 -->|calls| 431e2e3a_6c7a_74a1_c2ad_9e368d12f115
  05511be0_1e56_3876_59e2_7350fc912bb9["process()"]
  f618e317_1a72_981e_22c2_44b823813de7 -->|calls| 05511be0_1e56_3876_59e2_7350fc912bb9
  a199a3f7_5497_5329_2c7c_fc4555548da6["clear()"]
  f618e317_1a72_981e_22c2_44b823813de7 -->|calls| a199a3f7_5497_5329_2c7c_fc4555548da6
  style f618e317_1a72_981e_22c2_44b823813de7 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/svelte/src/internal/client/reactivity/batch.js lines 601–661

function flush_effects() {
	is_flushing = true;

	var source_stacks = DEV ? new Set() : null;

	try {
		var flush_count = 0;

		while (queued_root_effects.length > 0) {
			var batch = Batch.ensure();

			if (flush_count++ > 1000) {
				if (DEV) {
					var updates = new Map();

					for (const source of batch.current.keys()) {
						for (const [stack, update] of source.updated ?? []) {
							var entry = updates.get(stack);

							if (!entry) {
								entry = { error: update.error, count: 0 };
								updates.set(stack, entry);
							}

							entry.count += update.count;
						}
					}

					for (const update of updates.values()) {
						if (update.error) {
							// eslint-disable-next-line no-console
							console.error(update.error);
						}
					}
				}

				infinite_loop_guard();
			}

			batch.process(queued_root_effects);
			old_values.clear();

			if (DEV) {
				for (const source of batch.current.keys()) {
					/** @type {Set<Source>} */ (source_stacks).add(source);
				}
			}
		}
	} finally {
		queued_root_effects = [];

		is_flushing = false;
		last_scheduled_effect = null;

		if (DEV) {
			for (const source of /** @type {Set<Source>} */ (source_stacks)) {
				source.updated = null;
			}
		}
	}
}

Domain

Subdomains

Called By

Frequently Asked Questions

What does flush_effects() do?
flush_effects() is a function in the svelte codebase, defined in packages/svelte/src/internal/client/reactivity/batch.js.
Where is flush_effects() defined?
flush_effects() is defined in packages/svelte/src/internal/client/reactivity/batch.js at line 601.
What does flush_effects() call?
flush_effects() calls 6 function(s): clear, ensure, get, infinite_loop_guard, process, set.
What calls flush_effects()?
flush_effects() is called by 2 function(s): flush, flushSync.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free