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

Function subscribe

packages/svelte/src/store/shared/index.js:78–93  ·  view source on GitHub ↗

* @param {Subscriber<T>} run * @param {() => void} [invalidate] * @returns {Unsubscriber}

(run, invalidate = noop)

Source from the content-addressed store, hash-verified

76 * @returns {Unsubscriber}
77 */
78 function subscribe(run, invalidate = noop) {
79 /** @type {SubscribeInvalidateTuple<T>} */
80 const subscriber = [run, invalidate];
81 subscribers.add(subscriber);
82 if (subscribers.size === 1) {
83 stop = start(set, update) || noop;
84 }
85 run(/** @type {T} */ (value));
86 return () => {
87 subscribers.delete(subscriber);
88 if (subscribers.size === 0 && stop) {
89 stop();
90 stop = null;
91 }
92 };
93 }
94 return { set, update, subscribe };
95}
96

Callers 1

currentFunction · 0.50

Calls 4

stopFunction · 0.85
runFunction · 0.50
addMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected