Laptop-Thing/web/node_modules/.vite/deps/svelte_store.js.map

8 lines
5.3 KiB
Plaintext
Raw Permalink Normal View History

2024-11-27 12:35:48 -05:00
{
"version": 3,
"sources": ["../../svelte/src/store/index-client.js"],
"sourcesContent": ["/** @import { Readable, Writable } from './public.js' */\nimport { noop } from '../internal/shared/utils.js';\nimport {\n\teffect_root,\n\teffect_tracking,\n\trender_effect\n} from '../internal/client/reactivity/effects.js';\nimport { source } from '../internal/client/reactivity/sources.js';\nimport { get as get_source, tick } from '../internal/client/runtime.js';\nimport { increment } from '../reactivity/utils.js';\nimport { get, writable } from './shared/index.js';\n\nexport { derived, get, readable, readonly, writable } from './shared/index.js';\n\n/**\n * @template V\n * @overload\n * @param {() => V} get\n * @param {(v: V) => void} set\n * @returns {Writable<V>}\n */\n/**\n * @template V\n * @overload\n * @param {() => V} get\n * @returns {Readable<V>}\n */\n/**\n * Create a store from a function that returns state, and (to make a writable store), an\n * optional second function that sets state.\n *\n * ```ts\n * import { toStore } from 'svelte/store';\n *\n * let count = $state(0);\n *\n * const store = toStore(() => count, (v) => (count = v));\n * ```\n * @template V\n * @param {() => V} get\n * @param {(v: V) => void} [set]\n * @returns {Writable<V> | Readable<V>}\n */\nexport function toStore(get, set) {\n\tlet init_value = get();\n\tconst store = writable(init_value, (set) => {\n\t\t// If the value has changed before we call subscribe, then\n\t\t// we need to treat the value as already having run\n\t\tlet ran = init_value !== get();\n\n\t\t// TODO do we need a different implementation on the server?\n\t\tconst teardown = effect_root(() => {\n\t\t\trender_effect(() => {\n\t\t\t\tconst value = get();\n\t\t\t\tif (ran) set(value);\n\t\t\t});\n\t\t});\n\n\t\tran = true;\n\n\t\treturn teardown;\n\t});\n\n\tif (set) {\n\t\treturn {\n\t\t\tset,\n\t\t\tupdate: (fn) => set(fn(get())),\n\t\t\tsubscribe: store.subscribe\n\t\t};\n\t}\n\n\treturn {\n\t\tsubscribe: store.subscribe\n\t};\n}\n\n/**\n * @template V\n * @overload\n * @param {Writable<V>} store\n * @returns {{ current: V }}\n */\n/**\n * @template V\n * @overload\n * @param {Readable<V>} store\n * @returns {{ readonly current: V }}\n */\n/**\n * Convert a store to an object with a reactive `current` property. If `store`\n * is a readable store, `current` will be a readonly property.\n *\n * ```ts\n * import { fromStore, get, writable } from 'svelte/store';\n *\n * const store = writable(0);\n *\n * const count = fromStore(store);\n *\n * count.current; // 0;\n * store.set(1);\n * count.current; // 1\n *\n * count.current += 1;\n * get(store); // 2\n * ```\n * @template V\n * @param {Writable<V> | Readable<V>} store\n */\nexport function fromStore(store) {\n\tlet value = /** @type {V} */ (undefined);\n\tlet version = source(0);\n\tlet subscribers = 0;\n\n\tlet unsubscribe = noop;\n\n\tfunction current() {\n\t\tif (effect_tracking()) {\n\t\t\tget_source(version);\n\n\t\t\trender_effect(() => {\n\t\t\t\tif (subscribers === 0) {\n\t\t\t\t\tlet ran = false;\n\n\t\t\t\t\tunsubscribe = store.subscribe((v) => {\n\t\t\t\t\t\tvalue = v;\n\t\t\t\t\t\tif (ran) increment(version);\n\t\t\t\t\t});\n\n\t\t\t\t\tran = true;\n\t\t\t\t}\n\n\t\t\t\tsubscribers += 1;\n\n\t\t\t\treturn () => {\n\t\t\t\t\ttick().then(() => {\n\t\t\t\t\t\t// Only count down after timeout, else we would reach 0 before our own render effect reruns,\n\t\t\t\t\t\t// but reach 1 again when the tick callback of the prior teardown runs. That would mean we\n\t\t\t\t\t\t// re-subcribe unnecessarily and create a memory leak because the old subscription is never cleaned up.\n\t\t\t\t\t\tsubscribers -= 1;\n\n\t\t\t\t\t\tif (subscribers === 0) {\n\t\t\t\t\t\t\tunsubscribe();\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t};\n\t\t\t});\n\n\t\t\treturn value;\n\t\t}\n\n\t\treturn get(store);\n\t}\n\n\tif ('set' in store) {\n\t\treturn {\n\t\t\tget current() {\n\t\t\t\treturn current();\n\t\t\t},\n\t\t\tset current(v) {\n\t\t\t\tstore.set(v);\n\t\t\t}\n\t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