Home / File/ store.js — svelte Source File

store.js — svelte Source File

Architecture documentation for store.js, a javascript file in the svelte codebase. 14 imports, 2 dependents.

File javascript ClientRuntime Reactivity 14 imports 2 dependents 10 functions

Entity Profile

Dependency Diagram

graph LR
  49e6453b_f889_68d3_168f_19a644745ce8["store.js"]
  dacfcaf1_66cb_9fe3_083b_4fee2b4eb64f["utils.js"]
  49e6453b_f889_68d3_168f_19a644745ce8 --> dacfcaf1_66cb_9fe3_083b_4fee2b4eb64f
  257e3ffe_958d_4447_c42b_d1cd05172fdb["subscribe_to_store"]
  49e6453b_f889_68d3_168f_19a644745ce8 --> 257e3ffe_958d_4447_c42b_d1cd05172fdb
  b874f390_a6ee_7d84_7151_b2b77f0388d5["index.js"]
  49e6453b_f889_68d3_168f_19a644745ce8 --> b874f390_a6ee_7d84_7151_b2b77f0388d5
  4cf4c423_76ea_40eb_1692_69aae30c30f1["get"]
  49e6453b_f889_68d3_168f_19a644745ce8 --> 4cf4c423_76ea_40eb_1692_69aae30c30f1
  cb946435_ce66_d1e8_6bee_287bdb07e7c5["utils.js"]
  49e6453b_f889_68d3_168f_19a644745ce8 --> cb946435_ce66_d1e8_6bee_287bdb07e7c5
  fa007f2b_f437_c5ef_5c2d_ea8b5902500f["noop"]
  49e6453b_f889_68d3_168f_19a644745ce8 --> fa007f2b_f437_c5ef_5c2d_ea8b5902500f
  bde4209f_8ffc_1594_4024_b1835a44bcf6["runtime.js"]
  49e6453b_f889_68d3_168f_19a644745ce8 --> bde4209f_8ffc_1594_4024_b1835a44bcf6
  a08b6cc5_af73_1be4_d02f_3113cf8a8305["get"]
  49e6453b_f889_68d3_168f_19a644745ce8 --> a08b6cc5_af73_1be4_d02f_3113cf8a8305
  1ae6fa4e_16ee_acdf_5e28_17eb0819fddb["effects.js"]
  49e6453b_f889_68d3_168f_19a644745ce8 --> 1ae6fa4e_16ee_acdf_5e28_17eb0819fddb
  20340432_01a2_6741_abf4_60ccab51cdb3["teardown"]
  49e6453b_f889_68d3_168f_19a644745ce8 --> 20340432_01a2_6741_abf4_60ccab51cdb3
  e5c35d51_28d8_9054_923d_b7f82a3c8dc2["sources.js"]
  49e6453b_f889_68d3_168f_19a644745ce8 --> e5c35d51_28d8_9054_923d_b7f82a3c8dc2
  03788141_01d2_5299_6e22_4211e661afe4["mutable_source"]
  49e6453b_f889_68d3_168f_19a644745ce8 --> 03788141_01d2_5299_6e22_4211e661afe4
  63ee8247_ada4_9f1d_e139_0c1167cd5b1c["set"]
  49e6453b_f889_68d3_168f_19a644745ce8 --> 63ee8247_ada4_9f1d_e139_0c1167cd5b1c
  c9866d91_a204_fa55_a9e3_6bcc6aaaec1e["esm-env"]
  49e6453b_f889_68d3_168f_19a644745ce8 --> c9866d91_a204_fa55_a9e3_6bcc6aaaec1e
  style 49e6453b_f889_68d3_168f_19a644745ce8 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/** @import { StoreReferencesContainer } from '#client' */
/** @import { Store } from '#shared' */
import { subscribe_to_store } from '../../../store/utils.js';
import { get as get_store } from '../../../store/shared/index.js';
import { define_property, noop } from '../../shared/utils.js';
import { get } from '../runtime.js';
import { teardown } from './effects.js';
import { mutable_source, set } from './sources.js';
import { DEV } from 'esm-env';

/**
 * Whether or not the prop currently being read is a store binding, as in
 * `<Child bind:x={$y} />`. If it is, we treat the prop as mutable even in
 * runes mode, and skip `binding_property_non_reactive` validation
 */
let is_store_binding = false;

let IS_UNMOUNTED = Symbol();

/**
 * Gets the current value of a store. If the store isn't subscribed to yet, it will create a proxy
 * signal that will be updated when the store is. The store references container is needed to
 * track reassignments to stores and to track the correct component context.
 * @template V
 * @param {Store<V> | null | undefined} store
 * @param {string} store_name
 * @param {StoreReferencesContainer} stores
 * @returns {V}
 */
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);
				}
			});
// ... (144 more lines)

Domain

Subdomains

Frequently Asked Questions

What does store.js do?
store.js is a source file in the svelte codebase, written in javascript. It belongs to the ClientRuntime domain, Reactivity subdomain.
What functions are defined in store.js?
store.js defines 10 function(s): capture_store_binding, invalidate_store, mark_store_binding, setup_stores, store_get, store_mutate, store_set, store_unsub, update_pre_store, update_store.
What does store.js depend on?
store.js imports 14 module(s): effects.js, esm-env, get, get, index.js, mutable_source, noop, runtime.js, and 6 more.
What files import store.js?
store.js is imported by 2 file(s): props.js, validate.js.
Where is store.js in the architecture?
store.js is located at packages/svelte/src/internal/client/reactivity/store.js (domain: ClientRuntime, subdomain: Reactivity, directory: packages/svelte/src/internal/client/reactivity).

Analyze Your Own Codebase

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

Try Supermodel Free