MCPcopy
hub / github.com/sveltejs/svelte / store_get

Function store_get

packages/svelte/src/internal/server/index.js:243–262  ·  view source on GitHub ↗
(store_values, store_name, store)

Source from the content-addressed store, hash-verified

241 * @returns {V}
242 */
243export function store_get(store_values, store_name, store) {
244 if (DEV) {
245 validate_store(store, store_name.slice(1));
246 }
247
248 // it could be that someone eagerly updates the store in the instance script, so
249 // we should only reuse the store value in the template
250 if (store_name in store_values && store_values[store_name][0] === store) {
251 return store_values[store_name][2];
252 }
253
254 store_values[store_name]?.[1](); // if store was switched, unsubscribe from old store
255 store_values[store_name] = [store, null, undefined];
256 const unsub = subscribe_to_store(
257 store,
258 /** @param {any} v */ (v) => (store_values[store_name][2] = v)
259 );
260 store_values[store_name][1] = unsub;
261 return store_values[store_name][2];
262}
263
264/**
265 * Sets the new value of a store and returns that value.

Callers 3

store_mutateFunction · 0.70
update_storeFunction · 0.70
update_store_preFunction · 0.70

Calls 2

validate_storeFunction · 0.90
subscribe_to_storeFunction · 0.90

Tested by

no test coverage detected