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

110 lines
2.0 KiB
JavaScript
Raw Normal View History

2024-11-27 12:35:48 -05:00
import {
derived,
get as get2,
readable,
readonly,
writable
} from "./chunk-XWMO4EC7.js";
import {
increment
} from "./chunk-6NVL6SYI.js";
import "./chunk-XI64PIGS.js";
import "./chunk-FZEWDNFU.js";
import {
effect_root,
effect_tracking,
get,
noop,
render_effect,
source,
tick
} from "./chunk-OTO7APUV.js";
import "./chunk-EXIRPMAV.js";
import "./chunk-UGBVNEQM.js";
// node_modules/svelte/src/store/index-client.js
function toStore(get3, set) {
let init_value = get3();
const store = writable(init_value, (set2) => {
let ran = init_value !== get3();
const teardown = effect_root(() => {
render_effect(() => {
const value = get3();
if (ran) set2(value);
});
});
ran = true;
return teardown;
});
if (set) {
return {
set,
update: (fn) => set(fn(get3())),
subscribe: store.subscribe
};
}
return {
subscribe: store.subscribe
};
}
function fromStore(store) {
let value = (
/** @type {V} */
void 0
);
let version = source(0);
let subscribers = 0;
let unsubscribe = noop;
function current() {
if (effect_tracking()) {
get(version);
render_effect(() => {
if (subscribers === 0) {
let ran = false;
unsubscribe = store.subscribe((v) => {
value = v;
if (ran) increment(version);
});
ran = true;
}
subscribers += 1;
return () => {
tick().then(() => {
subscribers -= 1;
if (subscribers === 0) {
unsubscribe();
}
});
};
});
return value;
}
return get2(store);
}
if ("set" in store) {
return {
get current() {
return current();
},
set current(v) {
store.set(v);
}
};
}
return {
get current() {
return current();
}
};
}
export {
derived,
fromStore,
get2 as get,
readable,
readonly,
toStore,
writable
};
//# sourceMappingURL=svelte_store.js.map