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

Function subscribe_to_store

packages/svelte/src/store/utils.js:12–36  ·  view source on GitHub ↗
(store, run, invalidate)

Source from the content-addressed store, hash-verified

10 * @returns {() => void}
11 */
12export function subscribe_to_store(store, run, invalidate) {
13 if (store == null) {
14 // @ts-expect-error
15 run(undefined);
16
17 // @ts-expect-error
18 if (invalidate) invalidate(undefined);
19
20 return noop;
21 }
22
23 // Svelte store takes a private second argument
24 // StartStopNotifier could mutate state, and we want to silence the corresponding validation error
25 const unsub = untrack(() =>
26 store.subscribe(
27 run,
28 // @ts-expect-error
29 invalidate
30 )
31 );
32
33 // Also support RxJS
34 // @ts-expect-error TODO fix this in the types?
35 return unsub.unsubscribe ? () => unsub.unsubscribe() : unsub;
36}

Callers 4

derivedFunction · 0.90
getFunction · 0.90
store_getFunction · 0.90
store_getFunction · 0.90

Calls 3

untrackFunction · 0.90
subscribeMethod · 0.65
runFunction · 0.50

Tested by

no test coverage detected