Home / Function/ store_get() — svelte Function Reference

store_get() — svelte Function Reference

Architecture documentation for the store_get() function in store.js from the svelte codebase.

Entity Profile

Dependency Diagram

graph TD
  bd40e037_69e2_71b9_9d3d_0182230611c9["store_get()"]
  49e6453b_f889_68d3_168f_19a644745ce8["store.js"]
  bd40e037_69e2_71b9_9d3d_0182230611c9 -->|defined in| 49e6453b_f889_68d3_168f_19a644745ce8
  03788141_01d2_5299_6e22_4211e661afe4["mutable_source()"]
  bd40e037_69e2_71b9_9d3d_0182230611c9 -->|calls| 03788141_01d2_5299_6e22_4211e661afe4
  257e3ffe_958d_4447_c42b_d1cd05172fdb["subscribe_to_store()"]
  bd40e037_69e2_71b9_9d3d_0182230611c9 -->|calls| 257e3ffe_958d_4447_c42b_d1cd05172fdb
  63ee8247_ada4_9f1d_e139_0c1167cd5b1c["set()"]
  bd40e037_69e2_71b9_9d3d_0182230611c9 -->|calls| 63ee8247_ada4_9f1d_e139_0c1167cd5b1c
  a08b6cc5_af73_1be4_d02f_3113cf8a8305["get()"]
  bd40e037_69e2_71b9_9d3d_0182230611c9 -->|calls| a08b6cc5_af73_1be4_d02f_3113cf8a8305
  style bd40e037_69e2_71b9_9d3d_0182230611c9 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/svelte/src/internal/client/reactivity/store.js lines 30–74

export function store_get(store, store_name, stores) {
	const entry = (stores[store_name] ??= {
		store: null,
		source: mutable_source(undefined),
		unsubscribe: noop
	});

	if (DEV) {
		entry.source.label = store_name;
	}

	// if the component that setup this is already unmounted we don't want to register a subscription
	if (entry.store !== store && !(IS_UNMOUNTED in stores)) {
		entry.unsubscribe();
		entry.store = store ?? null;

		if (store == null) {
			entry.source.v = undefined; // see synchronous callback comment below
			entry.unsubscribe = noop;
		} else {
			var is_synchronous_callback = true;

			entry.unsubscribe = subscribe_to_store(store, (v) => {
				if (is_synchronous_callback) {
					// If the first updates to the store value (possibly multiple of them) are synchronously
					// inside a derived, we will hit the `state_unsafe_mutation` error if we `set` the value
					entry.source.v = v;
				} else {
					set(entry.source, v);
				}
			});

			is_synchronous_callback = false;
		}
	}

	// if the component that setup this stores is already unmounted the source will be out of sync
	// so we just use the `get` for the stores, less performant but it avoids to create a memory leak
	// and it will keep the value consistent
	if (store && IS_UNMOUNTED in stores) {
		return get_store(store);
	}

	return get(entry.source);
}

Domain

Subdomains

Frequently Asked Questions

What does store_get() do?
store_get() is a function in the svelte codebase, defined in packages/svelte/src/internal/client/reactivity/store.js.
Where is store_get() defined?
store_get() is defined in packages/svelte/src/internal/client/reactivity/store.js at line 30.
What does store_get() call?
store_get() calls 4 function(s): get, mutable_source, set, subscribe_to_store.

Analyze Your Own Codebase

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

Try Supermodel Free