@kdeveloper/kvark 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{index.d.ts → atom-DDF0_oHR.d.mts} +6 -5
- package/dist/atom-DDF0_oHR.d.mts.map +1 -0
- package/dist/family.d.mts +24 -0
- package/dist/family.d.mts.map +1 -0
- package/dist/family.mjs +2 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.mjs +2 -0
- package/dist/react/{index.d.ts → index.d.mts} +23 -14
- package/dist/react/index.d.mts.map +1 -0
- package/dist/react/index.mjs +69 -0
- package/dist/react/index.mjs.map +1 -0
- package/dist/store-BnIMQg3L.mjs +387 -0
- package/dist/store-BnIMQg3L.mjs.map +1 -0
- package/dist/store-D4q7TShr.d.mts +78 -0
- package/dist/store-D4q7TShr.d.mts.map +1 -0
- package/package.json +3 -3
- package/dist/chunk-6WIZ6MFN.js +0 -405
- package/dist/chunk-6WIZ6MFN.js.map +0 -1
- package/dist/family.d.ts +0 -23
- package/dist/family.js +0 -11
- package/dist/family.js.map +0 -1
- package/dist/index.js +0 -9
- package/dist/index.js.map +0 -1
- package/dist/react/index.js +0 -87
- package/dist/react/index.js.map +0 -1
- package/dist/store-DwEjhc31.d.ts +0 -70
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { h as AtomArgs, c as AtomState, d as AtomValue, I as IsWritable, S as StalePolicy, g as StoreClient, e as createStore } from './store-DwEjhc31.js';
|
|
1
|
+
import { f as WritableAtom, i as Atom, o as AtomConfig, p as WritableAtomContext } from "./store-D4q7TShr.mjs";
|
|
3
2
|
|
|
3
|
+
//#region src/internal/atom.d.ts
|
|
4
4
|
type WritableConfig<Value, Deps extends Record<string, Atom<unknown>>, Args extends readonly unknown[]> = AtomConfig<Value, Deps, Args> & {
|
|
5
|
-
|
|
5
|
+
set: (ctx: WritableAtomContext<Deps, Value>, ...args: Args) => Promise<void>;
|
|
6
6
|
};
|
|
7
7
|
type ReadonlyConfig<Value, Deps extends Record<string, Atom<unknown>>> = Omit<AtomConfig<Value, Deps, readonly []>, "set">;
|
|
8
8
|
declare function atom<Value, Deps extends Record<string, Atom<unknown>> = Record<never, never>, Args extends readonly unknown[] = readonly []>(config: WritableConfig<Value, Deps, Args>): WritableAtom<Value, Args>;
|
|
9
9
|
declare function atom<Value, Deps extends Record<string, Atom<unknown>> = Record<never, never>>(config: ReadonlyConfig<Value, Deps>): Atom<Value>;
|
|
10
|
-
|
|
11
|
-
export {
|
|
10
|
+
//#endregion
|
|
11
|
+
export { atom as t };
|
|
12
|
+
//# sourceMappingURL=atom-DDF0_oHR.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"atom-DDF0_oHR.d.mts","names":[],"sources":["../src/internal/atom.ts"],"mappings":";;;KASK,cAAA,qBAEU,MAAA,SAAe,IAAA,+CAE1B,UAAA,CAAW,KAAA,EAAO,IAAA,EAAM,IAAA;EAC1B,GAAA,GAAM,GAAA,EAAK,mBAAA,CAAoB,IAAA,EAAM,KAAA,MAAW,IAAA,EAAM,IAAA,KAAS,OAAA;AAAA;AAAA,KAG5D,cAAA,qBAAmC,MAAA,SAAe,IAAA,cAAkB,IAAA,CACvE,UAAA,CAAW,KAAA,EAAO,IAAA;AAAA,iBAIJ,IAAA,qBAED,MAAA,SAAe,IAAA,aAAiB,MAAA,8DAAA,CAE7C,MAAA,EAAQ,cAAA,CAAe,KAAA,EAAO,IAAA,EAAM,IAAA,IAAQ,YAAA,CAAa,KAAA,EAAO,IAAA;AAAA,iBAElD,IAAA,qBAAyB,MAAA,SAAe,IAAA,aAAiB,MAAA,eAAA,CACvE,MAAA,EAAQ,cAAA,CAAe,KAAA,EAAO,IAAA,IAC7B,IAAA,CAAK,KAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { c as AtomState, d as StalePolicy, f as WritableAtom, i as Atom, l as AtomValue, o as AtomConfig, r as createStore, s as AtomContext } from "./store-D4q7TShr.mjs";
|
|
2
|
+
import { t as atom } from "./atom-DDF0_oHR.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/internal/family.d.ts
|
|
5
|
+
type AtomFamilyOptions<Param, Value, Deps extends Record<string, Atom<unknown>>, Args extends readonly unknown[]> = {
|
|
6
|
+
dependencies?: (param: Param) => Deps;
|
|
7
|
+
stalePolicy?: StalePolicy;
|
|
8
|
+
cachePolicy?: "keep-all" | "lru";
|
|
9
|
+
lruSize?: number;
|
|
10
|
+
debugLabel?: string;
|
|
11
|
+
get: (param: Param) => (ctx: AtomContext<Deps>) => Promise<Value>;
|
|
12
|
+
set?: (param: Param) => (ctx: AtomContext<Deps>, ...args: Args) => Promise<void>;
|
|
13
|
+
};
|
|
14
|
+
interface AtomFamily<Param, Value> {
|
|
15
|
+
(param: Param): Atom<Value>;
|
|
16
|
+
invalidate(param: Param): void;
|
|
17
|
+
invalidateAll(): void;
|
|
18
|
+
remove(param: Param): void;
|
|
19
|
+
getCache(): ReadonlyMap<Param, Atom<Value>>;
|
|
20
|
+
}
|
|
21
|
+
declare function atomFamily<Param, Value, Deps extends Record<string, Atom<unknown>> = Record<never, never>, Args extends readonly unknown[] = readonly []>(options: AtomFamilyOptions<Param, Value, Deps, Args>): AtomFamily<Param, Value>;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { type Atom, type AtomConfig, type AtomContext, type AtomFamily, type AtomFamilyOptions, type AtomState, type AtomValue, type StalePolicy, type WritableAtom, atom, atomFamily, createStore };
|
|
24
|
+
//# sourceMappingURL=family.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"family.d.mts","names":[],"sources":["../src/internal/family.ts"],"mappings":";;;;KAIY,iBAAA,4BAGG,MAAA,SAAe,IAAA;EAG5B,YAAA,IAAgB,KAAA,EAAO,KAAA,KAAU,IAAA;EACjC,WAAA,GAAc,WAAA;EACd,WAAA;EACA,OAAA;EACA,UAAA;EACA,GAAA,GAAM,KAAA,EAAO,KAAA,MAAW,GAAA,EAAK,WAAA,CAAY,IAAA,MAAU,OAAA,CAAQ,KAAA;EAC3D,GAAA,IAAO,KAAA,EAAO,KAAA,MAAW,GAAA,EAAK,WAAA,CAAY,IAAA,MAAU,IAAA,EAAM,IAAA,KAAS,OAAA;AAAA;AAAA,UAGpD,UAAA;EAAA,CACd,KAAA,EAAO,KAAA,GAAQ,IAAA,CAAK,KAAA;EACrB,UAAA,CAAW,KAAA,EAAO,KAAA;EAClB,aAAA;EACA,MAAA,CAAO,KAAA,EAAO,KAAA;EACd,QAAA,IAAY,WAAA,CAAY,KAAA,EAAO,IAAA,CAAK,KAAA;AAAA;AAAA,iBAYtB,UAAA,4BAGD,MAAA,SAAe,IAAA,aAAiB,MAAA,8DAAA,CAE7C,OAAA,EAAS,iBAAA,CAAkB,KAAA,EAAO,KAAA,EAAO,IAAA,EAAM,IAAA,IAAQ,UAAA,CAAW,KAAA,EAAO,KAAA"}
|
package/dist/family.mjs
ADDED
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { a as AtomArgs, c as AtomState, d as StalePolicy, f as WritableAtom, i as Atom, l as AtomValue, n as StoreClient, o as AtomConfig, p as WritableAtomContext, r as createStore, s as AtomContext, u as IsWritable } from "./store-D4q7TShr.mjs";
|
|
2
|
+
import { t as atom } from "./atom-DDF0_oHR.mjs";
|
|
3
|
+
export { type Atom, type AtomArgs, type AtomConfig, type AtomContext, type AtomState, type AtomValue, type IsWritable, type StalePolicy, type StoreClient, type WritableAtom, type WritableAtomContext, atom, createStore };
|
package/dist/index.mjs
ADDED
|
@@ -1,27 +1,36 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { f as WritableAtom, i as Atom, n as StoreClient, t as Store } from "../store-D4q7TShr.mjs";
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
3
|
|
|
4
|
+
//#region src/react/provider.d.ts
|
|
4
5
|
type ProviderProps = {
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
store: Store;
|
|
7
|
+
children: ReactNode;
|
|
7
8
|
};
|
|
8
|
-
declare function Provider({
|
|
9
|
+
declare function Provider({
|
|
10
|
+
store,
|
|
11
|
+
children
|
|
12
|
+
}: ProviderProps): ReactNode;
|
|
9
13
|
declare function useStore(): Store;
|
|
10
|
-
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/react/use-atom-value.d.ts
|
|
11
16
|
type ObservedValue<V> = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
17
|
+
value: V;
|
|
18
|
+
isStale: boolean;
|
|
19
|
+
error: unknown;
|
|
15
20
|
};
|
|
16
21
|
declare function useAtomValue<V>(atom: Atom<V>): V;
|
|
17
22
|
declare function useAtomValue<V>(atom: Atom<V>, opts: {
|
|
18
|
-
|
|
23
|
+
observe: true;
|
|
19
24
|
}): ObservedValue<V>;
|
|
20
|
-
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/react/use-set-atom.d.ts
|
|
21
27
|
declare function useSetAtom<V, A extends readonly unknown[]>(atom: WritableAtom<V, A>): (...args: A) => Promise<void>;
|
|
22
|
-
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/react/use-atom.d.ts
|
|
23
30
|
declare function useAtom<V, A extends readonly unknown[]>(atom: WritableAtom<V, A>): readonly [V, (...args: A) => Promise<void>];
|
|
24
|
-
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/react/use-atom-callback.d.ts
|
|
25
33
|
declare function useAtomCallback<R>(callback: (ctx: StoreClient) => Promise<R>): () => Promise<R>;
|
|
26
|
-
|
|
34
|
+
//#endregion
|
|
27
35
|
export { Provider, useAtom, useAtomCallback, useAtomValue, useSetAtom, useStore };
|
|
36
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/react/provider.tsx","../../src/react/use-atom-value.ts","../../src/react/use-set-atom.ts","../../src/react/use-atom.ts","../../src/react/use-atom-callback.ts"],"mappings":";;;;KAKY,aAAA;EACV,KAAA,EAAO,KAAA;EACP,QAAA,EAAU,SAAA;AAAA;AAAA,iBAGI,QAAA,CAAA;EAAW,KAAA;EAAO;AAAA,GAAY,aAAA,GAAgB,SAAA;AAAA,iBAI9C,QAAA,CAAA,GAAY,KAAA;;;KCTvB,aAAA;EACH,KAAA,EAAO,CAAA;EACP,OAAA;EACA,KAAA;AAAA;AAAA,iBAGc,YAAA,GAAA,CAAgB,IAAA,EAAM,IAAA,CAAK,CAAA,IAAK,CAAA;AAAA,iBAChC,YAAA,GAAA,CAAgB,IAAA,EAAM,IAAA,CAAK,CAAA,GAAI,IAAA;EAAQ,OAAA;AAAA,IAAkB,aAAA,CAAc,CAAA;;;iBCRvE,UAAA,iCAAA,CACd,IAAA,EAAM,YAAA,CAAa,CAAA,EAAG,CAAA,QACjB,IAAA,EAAM,CAAA,KAAM,OAAA;;;iBCFH,OAAA,iCAAA,CACd,IAAA,EAAM,YAAA,CAAa,CAAA,EAAG,CAAA,cACX,CAAA,MAAO,IAAA,EAAM,CAAA,KAAM,OAAA;;;iBCFhB,eAAA,GAAA,CAAmB,QAAA,GAAW,GAAA,EAAK,WAAA,KAAgB,OAAA,CAAQ,CAAA,UAAW,OAAA,CAAQ,CAAA"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { i as CONFIG } from "../store-BnIMQg3L.mjs";
|
|
2
|
+
import { createContext, useCallback, useContext, useSyncExternalStore } from "react";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
//#region src/react/provider.tsx
|
|
5
|
+
const StoreContext = createContext(null);
|
|
6
|
+
function Provider({ store, children }) {
|
|
7
|
+
return /* @__PURE__ */ jsx(StoreContext, {
|
|
8
|
+
value: store,
|
|
9
|
+
children
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
function useStore() {
|
|
13
|
+
const store = useContext(StoreContext);
|
|
14
|
+
if (store == null) throw new Error("useStore must be used within a <Provider>");
|
|
15
|
+
return store;
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/react/use-atom-value.ts
|
|
19
|
+
function useAtomValue(atom, opts) {
|
|
20
|
+
const store = useStore();
|
|
21
|
+
const snapshot = useSyncExternalStore((notify) => store.subscribe(atom, notify), () => store.getSnapshot(atom), () => store.getServerSnapshot(atom));
|
|
22
|
+
const stalePolicy = atom[CONFIG].stalePolicy ?? "keep";
|
|
23
|
+
if (snapshot.status === "pending") throw store.resolve(atom);
|
|
24
|
+
if (snapshot.status === "stale") {
|
|
25
|
+
if (stalePolicy === "suspend") throw store.resolve(atom);
|
|
26
|
+
store.resolve(atom);
|
|
27
|
+
if (opts?.observe === true) return {
|
|
28
|
+
value: snapshot.value,
|
|
29
|
+
isStale: true,
|
|
30
|
+
error: void 0
|
|
31
|
+
};
|
|
32
|
+
return snapshot.value;
|
|
33
|
+
}
|
|
34
|
+
if (snapshot.status === "error") {
|
|
35
|
+
if (opts?.observe === true && snapshot.value !== void 0) return {
|
|
36
|
+
value: snapshot.value,
|
|
37
|
+
isStale: false,
|
|
38
|
+
error: snapshot.error
|
|
39
|
+
};
|
|
40
|
+
throw snapshot.error;
|
|
41
|
+
}
|
|
42
|
+
if (opts?.observe === true) return {
|
|
43
|
+
value: snapshot.value,
|
|
44
|
+
isStale: false,
|
|
45
|
+
error: void 0
|
|
46
|
+
};
|
|
47
|
+
return snapshot.value;
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/react/use-set-atom.ts
|
|
51
|
+
function useSetAtom(atom) {
|
|
52
|
+
const store = useStore();
|
|
53
|
+
return useCallback((...args) => store.set(atom, ...args), [store, atom]);
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/react/use-atom.ts
|
|
57
|
+
function useAtom(atom) {
|
|
58
|
+
return [useAtomValue(atom), useSetAtom(atom)];
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region src/react/use-atom-callback.ts
|
|
62
|
+
function useAtomCallback(callback) {
|
|
63
|
+
const store = useStore();
|
|
64
|
+
return useCallback(() => callback(store.getClient()), [store, callback]);
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
export { Provider, useAtom, useAtomCallback, useAtomValue, useSetAtom, useStore };
|
|
68
|
+
|
|
69
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/react/provider.tsx","../../src/react/use-atom-value.ts","../../src/react/use-set-atom.ts","../../src/react/use-atom.ts","../../src/react/use-atom-callback.ts"],"sourcesContent":["import { createContext, useContext, type ReactNode } from \"react\";\nimport { Store } from \"../internal/store.js\";\n\nconst StoreContext = createContext<Store | null>(null);\n\nexport type ProviderProps = {\n store: Store;\n children: ReactNode;\n};\n\nexport function Provider({ store, children }: ProviderProps): ReactNode {\n return <StoreContext value={store}>{children}</StoreContext>;\n}\n\nexport function useStore(): Store {\n const store = useContext(StoreContext);\n if (store == null) {\n throw new Error(\"useStore must be used within a <Provider>\");\n }\n return store;\n}\n","import { useSyncExternalStore } from \"react\";\nimport type { Atom, AtomState, StalePolicy } from \"../internal/types.js\";\nimport { CONFIG } from \"../internal/types.js\";\nimport { useStore } from \"./provider.js\";\n\ntype ObservedValue<V> = {\n value: V;\n isStale: boolean;\n error: unknown;\n};\n\nexport function useAtomValue<V>(atom: Atom<V>): V;\nexport function useAtomValue<V>(atom: Atom<V>, opts: { observe: true }): ObservedValue<V>;\nexport function useAtomValue<V>(atom: Atom<V>, opts?: { observe: true }): V | ObservedValue<V> {\n const store = useStore();\n\n const snapshot: AtomState<V> = useSyncExternalStore(\n (notify) => store.subscribe(atom, notify),\n () => store.getSnapshot(atom),\n () => store.getServerSnapshot(atom),\n );\n\n const stalePolicy: StalePolicy = atom[CONFIG].stalePolicy ?? \"keep\";\n\n if (snapshot.status === \"pending\") {\n throw store.resolve(atom);\n }\n\n if (snapshot.status === \"stale\") {\n if (stalePolicy === \"suspend\") {\n throw store.resolve(atom);\n }\n // \"keep\" or \"reset\" while stale: trigger background revalidation\n void store.resolve(atom);\n\n if (opts?.observe === true) {\n return { value: snapshot.value, isStale: true, error: undefined };\n }\n return snapshot.value;\n }\n\n if (snapshot.status === \"error\") {\n if (opts?.observe === true && snapshot.value !== undefined) {\n return {\n value: snapshot.value as V,\n isStale: false,\n error: snapshot.error,\n };\n }\n throw snapshot.error;\n }\n\n // status === \"fresh\"\n if (opts?.observe === true) {\n return { value: snapshot.value, isStale: false, error: undefined };\n }\n return snapshot.value;\n}\n","import { useCallback } from \"react\";\nimport type { WritableAtom } from \"../internal/types.js\";\nimport { useStore } from \"./provider.js\";\n\nexport function useSetAtom<V, A extends readonly unknown[]>(\n atom: WritableAtom<V, A>,\n): (...args: A) => Promise<void> {\n const store = useStore();\n return useCallback((...args: A): Promise<void> => store.set(atom, ...args), [store, atom]);\n}\n","import type { WritableAtom } from \"../internal/types.js\";\nimport { useAtomValue } from \"./use-atom-value.js\";\nimport { useSetAtom } from \"./use-set-atom.js\";\n\nexport function useAtom<V, A extends readonly unknown[]>(\n atom: WritableAtom<V, A>,\n): readonly [V, (...args: A) => Promise<void>] {\n const value = useAtomValue(atom);\n const setter = useSetAtom(atom);\n return [value, setter] as const;\n}\n","import { useCallback } from \"react\";\nimport type { StoreClient } from \"../internal/store.js\";\nimport { useStore } from \"./provider.js\";\n\nexport function useAtomCallback<R>(callback: (ctx: StoreClient) => Promise<R>): () => Promise<R> {\n const store = useStore();\n return useCallback((): Promise<R> => callback(store.getClient()), [store, callback]);\n}\n"],"mappings":";;;;AAGA,MAAM,eAAe,cAA4B,KAAK;AAOtD,SAAgB,SAAS,EAAE,OAAO,YAAsC;AACtE,QAAO,oBAAC,cAAD;EAAc,OAAO;EAAQ;EAAwB,CAAA;;AAG9D,SAAgB,WAAkB;CAChC,MAAM,QAAQ,WAAW,aAAa;AACtC,KAAI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//#region src/internal/types.ts
|
|
2
|
+
const CONFIG = Symbol("kvark.config");
|
|
3
|
+
const WRITABLE = Symbol("kvark.writable");
|
|
4
|
+
const FAMILY_LINK = Symbol("kvark.familyLink");
|
|
5
|
+
//#endregion
|
|
6
|
+
//#region src/internal/atom.ts
|
|
7
|
+
function atom(config) {
|
|
8
|
+
const internal = Object.create(null);
|
|
9
|
+
internal.get = config.get;
|
|
10
|
+
if (config.debugLabel != null) internal.debugLabel = config.debugLabel;
|
|
11
|
+
if (config.dependencies != null) internal.dependencies = config.dependencies;
|
|
12
|
+
if (config.stalePolicy != null) internal.stalePolicy = config.stalePolicy;
|
|
13
|
+
if (config.set != null) internal.set = config.set;
|
|
14
|
+
if (config.onMount != null) internal.onMount = config.onMount;
|
|
15
|
+
if (config.set != null) return {
|
|
16
|
+
[CONFIG]: internal,
|
|
17
|
+
[WRITABLE]: [],
|
|
18
|
+
debugLabel: config.debugLabel
|
|
19
|
+
};
|
|
20
|
+
return {
|
|
21
|
+
[CONFIG]: internal,
|
|
22
|
+
debugLabel: config.debugLabel
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/internal/family.ts
|
|
27
|
+
function getFamilyLink(target) {
|
|
28
|
+
return target[FAMILY_LINK];
|
|
29
|
+
}
|
|
30
|
+
function atomFamily(options) {
|
|
31
|
+
const cachePolicy = options.cachePolicy ?? "keep-all";
|
|
32
|
+
const lruSize = options.lruSize ?? 100;
|
|
33
|
+
const cache = /* @__PURE__ */ new Map();
|
|
34
|
+
const lruOrder = [];
|
|
35
|
+
const storeCallbacks = /* @__PURE__ */ new Set();
|
|
36
|
+
const link = {
|
|
37
|
+
invalidateAtom(target) {
|
|
38
|
+
for (const cb of storeCallbacks) cb(target);
|
|
39
|
+
},
|
|
40
|
+
registerStore(cb) {
|
|
41
|
+
storeCallbacks.add(cb);
|
|
42
|
+
return () => {
|
|
43
|
+
storeCallbacks.delete(cb);
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
function attachLink(target) {
|
|
48
|
+
target[FAMILY_LINK] = link;
|
|
49
|
+
}
|
|
50
|
+
function getOrCreate(param) {
|
|
51
|
+
const cached = cache.get(param);
|
|
52
|
+
if (cached != null) {
|
|
53
|
+
if (cachePolicy === "lru") touchLru(param);
|
|
54
|
+
return cached;
|
|
55
|
+
}
|
|
56
|
+
const deps = options.dependencies?.(param);
|
|
57
|
+
const getFn = options.get(param);
|
|
58
|
+
const setFn = options.set?.(param);
|
|
59
|
+
const created = createAtom(options.debugLabel != null ? `${options.debugLabel}(${String(param)})` : void 0, deps, getFn, setFn);
|
|
60
|
+
attachLink(created);
|
|
61
|
+
cache.set(param, created);
|
|
62
|
+
if (cachePolicy === "lru") {
|
|
63
|
+
lruOrder.push(param);
|
|
64
|
+
evictLru();
|
|
65
|
+
}
|
|
66
|
+
return created;
|
|
67
|
+
}
|
|
68
|
+
function createAtom(label, deps, getFn, setFn) {
|
|
69
|
+
const base = { get: getFn };
|
|
70
|
+
if (label != null) base.debugLabel = label;
|
|
71
|
+
if (deps != null) base.dependencies = deps;
|
|
72
|
+
if (options.stalePolicy != null) base.stalePolicy = options.stalePolicy;
|
|
73
|
+
if (setFn != null) {
|
|
74
|
+
base.set = setFn;
|
|
75
|
+
return atom(base);
|
|
76
|
+
}
|
|
77
|
+
return atom(base);
|
|
78
|
+
}
|
|
79
|
+
function touchLru(param) {
|
|
80
|
+
const idx = lruOrder.indexOf(param);
|
|
81
|
+
if (idx !== -1) lruOrder.splice(idx, 1);
|
|
82
|
+
lruOrder.push(param);
|
|
83
|
+
}
|
|
84
|
+
function evictLru() {
|
|
85
|
+
while (lruOrder.length > lruSize) {
|
|
86
|
+
const evicted = lruOrder.shift();
|
|
87
|
+
if (evicted !== void 0) cache.delete(evicted);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const family = getOrCreate;
|
|
91
|
+
family.invalidate = (param) => {
|
|
92
|
+
const cached = cache.get(param);
|
|
93
|
+
if (cached != null) link.invalidateAtom(cached);
|
|
94
|
+
};
|
|
95
|
+
family.invalidateAll = () => {
|
|
96
|
+
for (const cached of cache.values()) link.invalidateAtom(cached);
|
|
97
|
+
};
|
|
98
|
+
family.remove = (param) => {
|
|
99
|
+
cache.delete(param);
|
|
100
|
+
if (cachePolicy === "lru") {
|
|
101
|
+
const idx = lruOrder.indexOf(param);
|
|
102
|
+
if (idx !== -1) lruOrder.splice(idx, 1);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
family.getCache = () => cache;
|
|
106
|
+
return family;
|
|
107
|
+
}
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/internal/store.ts
|
|
110
|
+
const PENDING_STATE = {
|
|
111
|
+
status: "pending",
|
|
112
|
+
value: void 0,
|
|
113
|
+
error: void 0
|
|
114
|
+
};
|
|
115
|
+
var Store = class {
|
|
116
|
+
#atoms = /* @__PURE__ */ new WeakMap();
|
|
117
|
+
#rdeps = /* @__PURE__ */ new Map();
|
|
118
|
+
#pending = /* @__PURE__ */ new Set();
|
|
119
|
+
#controllers = /* @__PURE__ */ new WeakMap();
|
|
120
|
+
#familyUnsubs = /* @__PURE__ */ new Set();
|
|
121
|
+
#registeredFamilies = /* @__PURE__ */ new WeakSet();
|
|
122
|
+
#client = null;
|
|
123
|
+
#getOrCreate(atom) {
|
|
124
|
+
let entry = this.#atoms.get(atom);
|
|
125
|
+
if (entry == null) {
|
|
126
|
+
entry = {
|
|
127
|
+
state: PENDING_STATE,
|
|
128
|
+
version: 0,
|
|
129
|
+
promise: null,
|
|
130
|
+
listeners: /* @__PURE__ */ new Set(),
|
|
131
|
+
mountCount: 0,
|
|
132
|
+
unmount: null
|
|
133
|
+
};
|
|
134
|
+
this.#atoms.set(atom, entry);
|
|
135
|
+
}
|
|
136
|
+
return entry;
|
|
137
|
+
}
|
|
138
|
+
resolve(atom) {
|
|
139
|
+
const entry = this.#getOrCreate(atom);
|
|
140
|
+
if (entry.promise != null) return entry.promise;
|
|
141
|
+
const promise = this.#runGet(atom).finally(() => {
|
|
142
|
+
const e = this.#atoms.get(atom);
|
|
143
|
+
if (e != null) e.promise = null;
|
|
144
|
+
});
|
|
145
|
+
entry.promise = promise;
|
|
146
|
+
return promise;
|
|
147
|
+
}
|
|
148
|
+
async #runGet(atom) {
|
|
149
|
+
const config = atom[CONFIG];
|
|
150
|
+
const dependencies = config.dependencies;
|
|
151
|
+
const stalePolicy = config.stalePolicy ?? "keep";
|
|
152
|
+
const entry = this.#getOrCreate(atom);
|
|
153
|
+
if (dependencies != null) {
|
|
154
|
+
await Promise.all(Object.values(dependencies).map((dep) => this.resolve(dep)));
|
|
155
|
+
this.#registerRdeps(atom, dependencies);
|
|
156
|
+
}
|
|
157
|
+
const ctx = this.#makeCtx(atom, dependencies ?? {});
|
|
158
|
+
try {
|
|
159
|
+
const value = await config.get(ctx);
|
|
160
|
+
entry.state = {
|
|
161
|
+
status: "fresh",
|
|
162
|
+
value,
|
|
163
|
+
error: void 0
|
|
164
|
+
};
|
|
165
|
+
entry.version++;
|
|
166
|
+
this.#scheduleNotify(atom);
|
|
167
|
+
return value;
|
|
168
|
+
} catch (e) {
|
|
169
|
+
if (isAbortError(e)) throw e;
|
|
170
|
+
const prevValue = extractPreviousValue(entry.state);
|
|
171
|
+
entry.state = {
|
|
172
|
+
status: "error",
|
|
173
|
+
value: stalePolicy === "keep" ? prevValue : void 0,
|
|
174
|
+
error: e
|
|
175
|
+
};
|
|
176
|
+
entry.version++;
|
|
177
|
+
this.#scheduleNotify(atom);
|
|
178
|
+
throw e;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
invalidate(atom) {
|
|
182
|
+
this.#markStale(atom);
|
|
183
|
+
this.#pending.add(atom);
|
|
184
|
+
if (this.#pending.size === 1) queueMicrotask(() => {
|
|
185
|
+
this.#flushPending();
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
invalidateMany(atoms) {
|
|
189
|
+
for (const a of atoms) {
|
|
190
|
+
this.#markStale(a);
|
|
191
|
+
this.#pending.add(a);
|
|
192
|
+
}
|
|
193
|
+
if (this.#pending.size > 0) queueMicrotask(() => {
|
|
194
|
+
this.#flushPending();
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
#markStale(atom, visited = /* @__PURE__ */ new Set()) {
|
|
198
|
+
if (visited.has(atom)) return;
|
|
199
|
+
visited.add(atom);
|
|
200
|
+
const entry = this.#atoms.get(atom);
|
|
201
|
+
if (entry != null) {
|
|
202
|
+
const stalePolicy = atom[CONFIG].stalePolicy ?? "keep";
|
|
203
|
+
if (entry.state.status === "fresh") if (stalePolicy === "reset") entry.state = PENDING_STATE;
|
|
204
|
+
else entry.state = {
|
|
205
|
+
...entry.state,
|
|
206
|
+
status: "stale"
|
|
207
|
+
};
|
|
208
|
+
entry.promise = null;
|
|
209
|
+
this.#controllers.get(atom)?.abort();
|
|
210
|
+
}
|
|
211
|
+
const rdeps = this.#rdeps.get(atom);
|
|
212
|
+
if (rdeps != null) for (const dep of rdeps) this.#markStale(dep, visited);
|
|
213
|
+
}
|
|
214
|
+
#markReverseDependentsStale(atom) {
|
|
215
|
+
const rdeps = this.#rdeps.get(atom);
|
|
216
|
+
if (rdeps != null) {
|
|
217
|
+
const visited = new Set([atom]);
|
|
218
|
+
for (const dep of rdeps) {
|
|
219
|
+
this.#markStale(dep, visited);
|
|
220
|
+
this.#pending.add(dep);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
#flushPending() {
|
|
225
|
+
const batch = [...this.#pending];
|
|
226
|
+
this.#pending.clear();
|
|
227
|
+
const toNotify = /* @__PURE__ */ new Set();
|
|
228
|
+
for (const a of batch) {
|
|
229
|
+
const entry = this.#atoms.get(a);
|
|
230
|
+
if (entry != null) for (const l of entry.listeners) toNotify.add(l);
|
|
231
|
+
}
|
|
232
|
+
for (const l of toNotify) l();
|
|
233
|
+
}
|
|
234
|
+
#scheduleNotify(atom) {
|
|
235
|
+
this.#pending.add(atom);
|
|
236
|
+
if (this.#pending.size === 1) queueMicrotask(() => {
|
|
237
|
+
this.#flushPending();
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
#registerRdeps(atom, deps) {
|
|
241
|
+
for (const dep of Object.values(deps)) {
|
|
242
|
+
let set = this.#rdeps.get(dep);
|
|
243
|
+
if (set == null) {
|
|
244
|
+
set = /* @__PURE__ */ new Set();
|
|
245
|
+
this.#rdeps.set(dep, set);
|
|
246
|
+
}
|
|
247
|
+
set.add(atom);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
#makeCtx(atom, deps) {
|
|
251
|
+
this.#controllers.get(atom)?.abort();
|
|
252
|
+
const controller = new AbortController();
|
|
253
|
+
this.#controllers.set(atom, controller);
|
|
254
|
+
return {
|
|
255
|
+
signal: controller.signal,
|
|
256
|
+
get: async (key) => {
|
|
257
|
+
const dep = deps[key];
|
|
258
|
+
if (dep == null) throw new Error(`Unknown dependency key: "${String(key)}"`);
|
|
259
|
+
return this.resolve(dep);
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
subscribe(atom, listener) {
|
|
264
|
+
const entry = this.#getOrCreate(atom);
|
|
265
|
+
entry.listeners.add(listener);
|
|
266
|
+
this.#autoRegisterFamily(atom);
|
|
267
|
+
if (entry.state.status === "pending" && entry.promise == null) this.resolve(atom);
|
|
268
|
+
entry.mountCount++;
|
|
269
|
+
if (entry.mountCount === 1) {
|
|
270
|
+
const config = atom[CONFIG];
|
|
271
|
+
if (config.onMount != null) {
|
|
272
|
+
const setValue = (value) => {
|
|
273
|
+
entry.state = {
|
|
274
|
+
status: "fresh",
|
|
275
|
+
value,
|
|
276
|
+
error: void 0
|
|
277
|
+
};
|
|
278
|
+
entry.version++;
|
|
279
|
+
this.#scheduleNotify(atom);
|
|
280
|
+
};
|
|
281
|
+
const cleanup = config.onMount(setValue);
|
|
282
|
+
if (typeof cleanup === "function") entry.unmount = cleanup;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return () => {
|
|
286
|
+
entry.listeners.delete(listener);
|
|
287
|
+
entry.mountCount--;
|
|
288
|
+
if (entry.mountCount === 0 && entry.unmount != null) {
|
|
289
|
+
entry.unmount();
|
|
290
|
+
entry.unmount = null;
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
#autoRegisterFamily(atom) {
|
|
295
|
+
const link = getFamilyLink(atom);
|
|
296
|
+
if (link == null) return;
|
|
297
|
+
if (this.#registeredFamilies.has(link)) return;
|
|
298
|
+
this.#registeredFamilies.add(link);
|
|
299
|
+
const unsub = link.registerStore((target) => {
|
|
300
|
+
this.invalidate(target);
|
|
301
|
+
});
|
|
302
|
+
this.#familyUnsubs.add(unsub);
|
|
303
|
+
}
|
|
304
|
+
getSnapshot(atom) {
|
|
305
|
+
return this.#getOrCreate(atom).state;
|
|
306
|
+
}
|
|
307
|
+
getServerSnapshot(atom) {
|
|
308
|
+
const entry = this.#atoms.get(atom);
|
|
309
|
+
if (entry != null) return entry.state;
|
|
310
|
+
return PENDING_STATE;
|
|
311
|
+
}
|
|
312
|
+
async set(atom, ...args) {
|
|
313
|
+
const config = atom[CONFIG];
|
|
314
|
+
if (config.set == null) throw new Error(`Atom${atom.debugLabel != null ? ` "${atom.debugLabel}"` : ""} is not writable`);
|
|
315
|
+
const deps = config.dependencies ?? {};
|
|
316
|
+
const baseCtx = this.#makeCtx(atom, deps);
|
|
317
|
+
const entry = this.#getOrCreate(atom);
|
|
318
|
+
const optimisticSnapshot = { current: null };
|
|
319
|
+
const ctx = {
|
|
320
|
+
...baseCtx,
|
|
321
|
+
setOptimisticValue: (value) => {
|
|
322
|
+
if (optimisticSnapshot.current == null) optimisticSnapshot.current = {
|
|
323
|
+
state: entry.state,
|
|
324
|
+
version: entry.version
|
|
325
|
+
};
|
|
326
|
+
entry.state = {
|
|
327
|
+
status: "fresh",
|
|
328
|
+
value,
|
|
329
|
+
error: void 0
|
|
330
|
+
};
|
|
331
|
+
entry.version++;
|
|
332
|
+
this.#scheduleNotify(atom);
|
|
333
|
+
this.#markReverseDependentsStale(atom);
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
try {
|
|
337
|
+
await config.set(ctx, ...args);
|
|
338
|
+
} catch (e) {
|
|
339
|
+
const snap = optimisticSnapshot.current;
|
|
340
|
+
if (snap != null) {
|
|
341
|
+
entry.state = snap.state;
|
|
342
|
+
entry.version = snap.version;
|
|
343
|
+
this.#scheduleNotify(atom);
|
|
344
|
+
}
|
|
345
|
+
throw e;
|
|
346
|
+
}
|
|
347
|
+
this.invalidate(atom);
|
|
348
|
+
}
|
|
349
|
+
getClient() {
|
|
350
|
+
if (this.#client != null) return this.#client;
|
|
351
|
+
const store = this;
|
|
352
|
+
this.#client = {
|
|
353
|
+
get(atom) {
|
|
354
|
+
return store.resolve(atom);
|
|
355
|
+
},
|
|
356
|
+
set(atom, ...args) {
|
|
357
|
+
return store.set(atom, ...args);
|
|
358
|
+
},
|
|
359
|
+
invalidate(atom) {
|
|
360
|
+
store.invalidate(atom);
|
|
361
|
+
},
|
|
362
|
+
invalidateMany(atoms) {
|
|
363
|
+
store.invalidateMany(atoms);
|
|
364
|
+
},
|
|
365
|
+
subscribe(atom, listener) {
|
|
366
|
+
return store.subscribe(atom, () => {
|
|
367
|
+
listener(store.getSnapshot(atom));
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
return this.#client;
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
function createStore() {
|
|
375
|
+
return new Store();
|
|
376
|
+
}
|
|
377
|
+
function isAbortError(e) {
|
|
378
|
+
return e instanceof DOMException && e.name === "AbortError";
|
|
379
|
+
}
|
|
380
|
+
function extractPreviousValue(state) {
|
|
381
|
+
if (state.status === "stale" || state.status === "fresh") return state.value;
|
|
382
|
+
if (state.status === "error") return state.value;
|
|
383
|
+
}
|
|
384
|
+
//#endregion
|
|
385
|
+
export { CONFIG as i, atomFamily as n, atom as r, createStore as t };
|
|
386
|
+
|
|
387
|
+
//# sourceMappingURL=store-BnIMQg3L.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store-BnIMQg3L.mjs","names":["#atoms","#rdeps","#pending","#controllers","#familyUnsubs","#registeredFamilies","#getOrCreate","#runGet","#registerRdeps","#makeCtx","#scheduleNotify","#markStale","#flushPending","#autoRegisterFamily","#markReverseDependentsStale","#client"],"sources":["../src/internal/types.ts","../src/internal/atom.ts","../src/internal/family.ts","../src/internal/store.ts"],"sourcesContent":["export const CONFIG = Symbol(\"kvark.config\");\nexport const WRITABLE = Symbol(\"kvark.writable\");\nexport const FAMILY_LINK = Symbol(\"kvark.familyLink\");\n\nexport type AtomState<Value> =\n | { status: \"pending\"; value: undefined; error: undefined }\n | { status: \"stale\"; value: Value; error: undefined }\n | { status: \"fresh\"; value: Value; error: undefined }\n | { status: \"error\"; value: Value | undefined; error: unknown };\n\nexport type StalePolicy = \"keep\" | \"suspend\" | \"reset\";\n\nexport type AtomContext<Deps extends Record<string, Atom<unknown>>> = {\n get: <K extends keyof Deps>(key: K) => Promise<AtomValue<Deps[K]>>;\n signal: AbortSignal;\n};\n\nexport type WritableAtomContext<\n Deps extends Record<string, Atom<unknown>>,\n Value,\n> = AtomContext<Deps> & {\n setOptimisticValue: (value: Value) => void;\n};\n\nexport type AtomConfig<\n Value,\n Deps extends Record<string, Atom<unknown>>,\n Args extends readonly unknown[],\n> = {\n dependencies?: Deps;\n stalePolicy?: StalePolicy;\n debugLabel?: string;\n get: (ctx: AtomContext<Deps>) => Promise<Value>;\n set?: (ctx: WritableAtomContext<Deps, Value>, ...args: Args) => Promise<void>;\n onMount?: (set: (value: Value) => void) => (() => void) | void;\n};\n\nexport interface InternalAtomConfig<Value> {\n dependencies?: Record<string, Atom<unknown>>;\n stalePolicy?: StalePolicy;\n debugLabel?: string;\n get: (ctx: AtomContext<Record<string, Atom<unknown>>>) => Promise<Value>;\n set?: (\n ctx: WritableAtomContext<Record<string, Atom<unknown>>, Value>,\n ...args: readonly unknown[]\n ) => Promise<void>;\n onMount?: (set: (value: unknown) => void) => (() => void) | void;\n}\n\nexport interface Atom<out Value> {\n readonly [CONFIG]: InternalAtomConfig<Value>;\n readonly debugLabel: string | undefined;\n}\n\nexport interface WritableAtom<\n out Value,\n in out Args extends readonly unknown[],\n> extends Atom<Value> {\n readonly [WRITABLE]: Args;\n}\n\nexport type AtomValue<A> = A extends Atom<infer V> ? V : never;\nexport type IsWritable<A> = A extends WritableAtom<unknown, readonly unknown[]> ? true : false;\nexport type AtomArgs<A> = A extends WritableAtom<unknown, infer Args> ? Args : never;\n","import type {\n Atom,\n AtomConfig,\n InternalAtomConfig,\n WritableAtom,\n WritableAtomContext,\n} from \"./types.js\";\nimport { CONFIG, WRITABLE } from \"./types.js\";\n\ntype WritableConfig<\n Value,\n Deps extends Record<string, Atom<unknown>>,\n Args extends readonly unknown[],\n> = AtomConfig<Value, Deps, Args> & {\n set: (ctx: WritableAtomContext<Deps, Value>, ...args: Args) => Promise<void>;\n};\n\ntype ReadonlyConfig<Value, Deps extends Record<string, Atom<unknown>>> = Omit<\n AtomConfig<Value, Deps, readonly []>,\n \"set\"\n>;\n\nexport function atom<\n Value,\n Deps extends Record<string, Atom<unknown>> = Record<never, never>,\n Args extends readonly unknown[] = readonly [],\n>(config: WritableConfig<Value, Deps, Args>): WritableAtom<Value, Args>;\n\nexport function atom<Value, Deps extends Record<string, Atom<unknown>> = Record<never, never>>(\n config: ReadonlyConfig<Value, Deps>,\n): Atom<Value>;\n\nexport function atom<\n Value,\n Deps extends Record<string, Atom<unknown>> = Record<never, never>,\n Args extends readonly unknown[] = readonly [],\n>(config: AtomConfig<Value, Deps, Args>): Atom<Value> {\n const internal: InternalAtomConfig<Value> = Object.create(null) as InternalAtomConfig<Value>;\n internal.get = config.get as InternalAtomConfig<Value>[\"get\"];\n\n if (config.debugLabel != null) {\n internal.debugLabel = config.debugLabel;\n }\n if (config.dependencies != null) {\n internal.dependencies = config.dependencies as Record<string, Atom<unknown>>;\n }\n if (config.stalePolicy != null) {\n internal.stalePolicy = config.stalePolicy;\n }\n if (config.set != null) {\n internal.set = config.set as NonNullable<InternalAtomConfig<Value>[\"set\"]>;\n }\n if (config.onMount != null) {\n internal.onMount = config.onMount as NonNullable<InternalAtomConfig<Value>[\"onMount\"]>;\n }\n\n if (config.set != null) {\n return {\n [CONFIG]: internal,\n [WRITABLE]: [] as unknown as Args,\n debugLabel: config.debugLabel,\n } as unknown as Atom<Value>;\n }\n\n return {\n [CONFIG]: internal,\n debugLabel: config.debugLabel,\n } as Atom<Value>;\n}\n","import type { Atom, AtomContext, StalePolicy } from \"./types.js\";\nimport { FAMILY_LINK } from \"./types.js\";\nimport { atom } from \"./atom.js\";\n\nexport type AtomFamilyOptions<\n Param,\n Value,\n Deps extends Record<string, Atom<unknown>>,\n Args extends readonly unknown[],\n> = {\n dependencies?: (param: Param) => Deps;\n stalePolicy?: StalePolicy;\n cachePolicy?: \"keep-all\" | \"lru\";\n lruSize?: number;\n debugLabel?: string;\n get: (param: Param) => (ctx: AtomContext<Deps>) => Promise<Value>;\n set?: (param: Param) => (ctx: AtomContext<Deps>, ...args: Args) => Promise<void>;\n};\n\nexport interface AtomFamily<Param, Value> {\n (param: Param): Atom<Value>;\n invalidate(param: Param): void;\n invalidateAll(): void;\n remove(param: Param): void;\n getCache(): ReadonlyMap<Param, Atom<Value>>;\n}\n\nexport interface FamilyLink {\n invalidateAtom: (atom: Atom<unknown>) => void;\n registerStore: (cb: (atom: Atom<unknown>) => void) => () => void;\n}\n\nexport function getFamilyLink(target: Atom<unknown>): FamilyLink | undefined {\n return (target as unknown as Record<symbol, FamilyLink | undefined>)[FAMILY_LINK];\n}\n\nexport function atomFamily<\n Param,\n Value,\n Deps extends Record<string, Atom<unknown>> = Record<never, never>,\n Args extends readonly unknown[] = readonly [],\n>(options: AtomFamilyOptions<Param, Value, Deps, Args>): AtomFamily<Param, Value> {\n const cachePolicy = options.cachePolicy ?? \"keep-all\";\n const lruSize = options.lruSize ?? 100;\n const cache = new Map<Param, Atom<Value>>();\n const lruOrder: Param[] = [];\n const storeCallbacks = new Set<(atom: Atom<unknown>) => void>();\n\n const link: FamilyLink = {\n invalidateAtom(target: Atom<unknown>): void {\n for (const cb of storeCallbacks) {\n cb(target);\n }\n },\n registerStore(cb: (atom: Atom<unknown>) => void): () => void {\n storeCallbacks.add(cb);\n return () => {\n storeCallbacks.delete(cb);\n };\n },\n };\n\n function attachLink(target: Atom<Value>): void {\n (target as unknown as Record<symbol, FamilyLink>)[FAMILY_LINK] = link;\n }\n\n function getOrCreate(param: Param): Atom<Value> {\n const cached = cache.get(param);\n if (cached != null) {\n if (cachePolicy === \"lru\") {\n touchLru(param);\n }\n return cached;\n }\n\n const deps = options.dependencies?.(param);\n const getFn = options.get(param);\n const setFn = options.set?.(param);\n\n const label =\n options.debugLabel != null ? `${options.debugLabel}(${String(param)})` : undefined;\n\n const created = createAtom(label, deps, getFn, setFn);\n attachLink(created);\n cache.set(param, created);\n\n if (cachePolicy === \"lru\") {\n lruOrder.push(param);\n evictLru();\n }\n\n return created;\n }\n\n function createAtom(\n label: string | undefined,\n deps: Deps | undefined,\n getFn: (ctx: AtomContext<Deps>) => Promise<Value>,\n setFn: ((ctx: AtomContext<Deps>, ...args: Args) => Promise<void>) | undefined,\n ): Atom<Value> {\n const base = {\n get: getFn as (ctx: AtomContext<Deps>) => Promise<Value>,\n } as {\n debugLabel?: string;\n dependencies?: Deps;\n stalePolicy?: StalePolicy;\n get: (ctx: AtomContext<Deps>) => Promise<Value>;\n set?: (ctx: AtomContext<Deps>, ...args: Args) => Promise<void>;\n };\n\n if (label != null) {\n base.debugLabel = label;\n }\n if (deps != null) {\n base.dependencies = deps;\n }\n if (options.stalePolicy != null) {\n base.stalePolicy = options.stalePolicy;\n }\n\n if (setFn != null) {\n base.set = setFn;\n return atom(\n base as typeof base & {\n set: (ctx: AtomContext<Deps>, ...args: Args) => Promise<void>;\n },\n ) as Atom<Value>;\n }\n\n return atom(base as Omit<typeof base, \"set\">);\n }\n\n function touchLru(param: Param): void {\n const idx = lruOrder.indexOf(param);\n if (idx !== -1) {\n lruOrder.splice(idx, 1);\n }\n lruOrder.push(param);\n }\n\n function evictLru(): void {\n while (lruOrder.length > lruSize) {\n const evicted = lruOrder.shift();\n if (evicted !== undefined) {\n cache.delete(evicted);\n }\n }\n }\n\n const family = getOrCreate as AtomFamily<Param, Value>;\n\n family.invalidate = (param: Param): void => {\n const cached = cache.get(param);\n if (cached != null) {\n link.invalidateAtom(cached);\n }\n };\n\n family.invalidateAll = (): void => {\n for (const cached of cache.values()) {\n link.invalidateAtom(cached);\n }\n };\n\n family.remove = (param: Param): void => {\n cache.delete(param);\n if (cachePolicy === \"lru\") {\n const idx = lruOrder.indexOf(param);\n if (idx !== -1) {\n lruOrder.splice(idx, 1);\n }\n }\n };\n\n family.getCache = (): ReadonlyMap<Param, Atom<Value>> => cache;\n\n return family;\n}\n","import type {\n Atom,\n AtomContext,\n AtomState,\n InternalAtomConfig,\n StalePolicy,\n WritableAtom,\n WritableAtomContext,\n} from \"./types.js\";\nimport { CONFIG } from \"./types.js\";\nimport { getFamilyLink } from \"./family.js\";\n\ntype AtomEntry<V> = {\n state: AtomState<V>;\n version: number;\n promise: Promise<V> | null;\n listeners: Set<() => void>;\n mountCount: number;\n unmount: (() => void) | null;\n};\n\nexport interface StoreClient {\n get<V>(atom: Atom<V>): Promise<V>;\n set<V, A extends readonly unknown[]>(atom: WritableAtom<V, A>, ...args: A): Promise<void>;\n invalidate(atom: Atom<unknown>): void;\n invalidateMany(atoms: ReadonlyArray<Atom<unknown>>): void;\n subscribe<V>(atom: Atom<V>, listener: (state: AtomState<V>) => void): () => void;\n}\n\nconst PENDING_STATE: AtomState<never> = {\n status: \"pending\",\n value: undefined,\n error: undefined,\n} as AtomState<never>;\n\nexport class Store {\n readonly #atoms = new WeakMap<Atom<unknown>, AtomEntry<unknown>>();\n readonly #rdeps = new Map<Atom<unknown>, Set<Atom<unknown>>>();\n readonly #pending = new Set<Atom<unknown>>();\n readonly #controllers = new WeakMap<Atom<unknown>, AbortController>();\n readonly #familyUnsubs = new Set<() => void>();\n readonly #registeredFamilies = new WeakSet<object>();\n #client: StoreClient | null = null;\n\n #getOrCreate<V>(atom: Atom<V>): AtomEntry<V> {\n let entry = this.#atoms.get(atom) as AtomEntry<V> | undefined;\n if (entry == null) {\n entry = {\n state: PENDING_STATE as AtomState<V>,\n version: 0,\n promise: null,\n listeners: new Set(),\n mountCount: 0,\n unmount: null,\n };\n this.#atoms.set(atom, entry as AtomEntry<unknown>);\n }\n return entry;\n }\n\n resolve<V>(atom: Atom<V>): Promise<V> {\n const entry = this.#getOrCreate(atom);\n if (entry.promise != null) {\n return entry.promise;\n }\n\n const promise = this.#runGet(atom).finally(() => {\n const e = this.#atoms.get(atom) as AtomEntry<V> | undefined;\n if (e != null) {\n e.promise = null;\n }\n });\n entry.promise = promise;\n return promise;\n }\n\n async #runGet<V>(atom: Atom<V>): Promise<V> {\n const config: InternalAtomConfig<V> = atom[CONFIG];\n const dependencies = config.dependencies;\n const stalePolicy: StalePolicy = config.stalePolicy ?? \"keep\";\n const entry = this.#getOrCreate(atom);\n\n if (dependencies != null) {\n await Promise.all(Object.values(dependencies).map((dep) => this.resolve(dep)));\n this.#registerRdeps(atom, dependencies);\n }\n\n const ctx = this.#makeCtx(atom, dependencies ?? {});\n\n try {\n const value = await config.get(ctx);\n entry.state = { status: \"fresh\", value, error: undefined };\n entry.version++;\n this.#scheduleNotify(atom);\n return value;\n } catch (e: unknown) {\n if (isAbortError(e)) {\n throw e;\n }\n const prevValue = extractPreviousValue<V>(entry.state);\n entry.state = {\n status: \"error\",\n value: stalePolicy === \"keep\" ? prevValue : undefined,\n error: e,\n } as AtomState<V>;\n entry.version++;\n this.#scheduleNotify(atom);\n throw e;\n }\n }\n\n invalidate(atom: Atom<unknown>): void {\n this.#markStale(atom);\n this.#pending.add(atom);\n if (this.#pending.size === 1) {\n queueMicrotask(() => {\n this.#flushPending();\n });\n }\n }\n\n invalidateMany(atoms: ReadonlyArray<Atom<unknown>>): void {\n for (const a of atoms) {\n this.#markStale(a);\n this.#pending.add(a);\n }\n if (this.#pending.size > 0) {\n queueMicrotask(() => {\n this.#flushPending();\n });\n }\n }\n\n #markStale(atom: Atom<unknown>, visited = new Set<Atom<unknown>>()): void {\n if (visited.has(atom)) {\n return;\n }\n visited.add(atom);\n\n const entry = this.#atoms.get(atom);\n if (entry != null) {\n const stalePolicy: StalePolicy = atom[CONFIG].stalePolicy ?? \"keep\";\n\n if (entry.state.status === \"fresh\") {\n if (stalePolicy === \"reset\") {\n entry.state = PENDING_STATE;\n } else {\n entry.state = { ...entry.state, status: \"stale\" };\n }\n }\n\n entry.promise = null;\n this.#controllers.get(atom)?.abort();\n }\n\n const rdeps = this.#rdeps.get(atom);\n if (rdeps != null) {\n for (const dep of rdeps) {\n this.#markStale(dep, visited);\n }\n }\n }\n\n #markReverseDependentsStale(atom: Atom<unknown>): void {\n const rdeps = this.#rdeps.get(atom);\n if (rdeps != null) {\n const visited = new Set<Atom<unknown>>([atom]);\n for (const dep of rdeps) {\n this.#markStale(dep, visited);\n this.#pending.add(dep);\n }\n }\n }\n\n #flushPending(): void {\n const batch = [...this.#pending];\n this.#pending.clear();\n const toNotify = new Set<() => void>();\n for (const a of batch) {\n const entry = this.#atoms.get(a);\n if (entry != null) {\n for (const l of entry.listeners) {\n toNotify.add(l);\n }\n }\n }\n for (const l of toNotify) {\n l();\n }\n }\n\n #scheduleNotify(atom: Atom<unknown>): void {\n this.#pending.add(atom);\n if (this.#pending.size === 1) {\n queueMicrotask(() => {\n this.#flushPending();\n });\n }\n }\n\n #registerRdeps(atom: Atom<unknown>, deps: Record<string, Atom<unknown>>): void {\n for (const dep of Object.values(deps)) {\n let set = this.#rdeps.get(dep);\n if (set == null) {\n set = new Set();\n this.#rdeps.set(dep, set);\n }\n set.add(atom);\n }\n }\n\n #makeCtx(\n atom: Atom<unknown>,\n deps: Record<string, Atom<unknown>>,\n ): AtomContext<Record<string, Atom<unknown>>> {\n this.#controllers.get(atom)?.abort();\n const controller = new AbortController();\n this.#controllers.set(atom, controller);\n\n return {\n signal: controller.signal,\n get: async (key: string) => {\n const dep = deps[key];\n if (dep == null) {\n throw new Error(`Unknown dependency key: \"${String(key)}\"`);\n }\n return this.resolve(dep);\n },\n };\n }\n\n subscribe<V>(atom: Atom<V>, listener: () => void): () => void {\n const entry = this.#getOrCreate(atom);\n entry.listeners.add(listener);\n\n this.#autoRegisterFamily(atom);\n\n if (entry.state.status === \"pending\" && entry.promise == null) {\n void this.resolve(atom);\n }\n\n entry.mountCount++;\n if (entry.mountCount === 1) {\n const config: InternalAtomConfig<V> = atom[CONFIG];\n if (config.onMount != null) {\n const setValue = (value: V): void => {\n entry.state = { status: \"fresh\", value, error: undefined };\n entry.version++;\n this.#scheduleNotify(atom);\n };\n const cleanup = config.onMount(setValue as (value: unknown) => void);\n if (typeof cleanup === \"function\") {\n entry.unmount = cleanup;\n }\n }\n }\n\n return () => {\n entry.listeners.delete(listener);\n entry.mountCount--;\n if (entry.mountCount === 0 && entry.unmount != null) {\n entry.unmount();\n entry.unmount = null;\n }\n };\n }\n\n #autoRegisterFamily(atom: Atom<unknown>): void {\n const link = getFamilyLink(atom);\n if (link == null) {\n return;\n }\n if (this.#registeredFamilies.has(link)) {\n return;\n }\n this.#registeredFamilies.add(link);\n const unsub = link.registerStore((target: Atom<unknown>) => {\n this.invalidate(target);\n });\n this.#familyUnsubs.add(unsub);\n }\n\n getSnapshot<V>(atom: Atom<V>): AtomState<V> {\n return this.#getOrCreate(atom).state;\n }\n\n getServerSnapshot<V>(atom: Atom<V>): AtomState<V> {\n const entry = this.#atoms.get(atom) as AtomEntry<V> | undefined;\n if (entry != null) {\n return entry.state;\n }\n return PENDING_STATE as AtomState<V>;\n }\n\n async set<V, A extends readonly unknown[]>(atom: WritableAtom<V, A>, ...args: A): Promise<void> {\n const config: InternalAtomConfig<V> = atom[CONFIG];\n if (config.set == null) {\n throw new Error(\n `Atom${atom.debugLabel != null ? ` \"${atom.debugLabel}\"` : \"\"} is not writable`,\n );\n }\n\n const deps = config.dependencies ?? {};\n const baseCtx = this.#makeCtx(atom, deps);\n const entry = this.#getOrCreate(atom);\n\n // Ref: assignments inside setOptimisticValue are not tracked on a plain `let` for catch narrowing.\n const optimisticSnapshot: {\n current: { state: AtomState<V>; version: number } | null;\n } = { current: null };\n\n const ctx: WritableAtomContext<Record<string, Atom<unknown>>, V> = {\n ...baseCtx,\n setOptimisticValue: (value: V): void => {\n if (optimisticSnapshot.current == null) {\n optimisticSnapshot.current = { state: entry.state, version: entry.version };\n }\n entry.state = { status: \"fresh\", value, error: undefined };\n entry.version++;\n this.#scheduleNotify(atom);\n this.#markReverseDependentsStale(atom);\n },\n };\n\n try {\n await config.set(ctx, ...args);\n } catch (e: unknown) {\n const snap = optimisticSnapshot.current;\n if (snap != null) {\n entry.state = snap.state;\n entry.version = snap.version;\n this.#scheduleNotify(atom);\n }\n throw e;\n }\n\n this.invalidate(atom);\n }\n\n getClient(): StoreClient {\n if (this.#client != null) {\n return this.#client;\n }\n\n const store = this;\n this.#client = {\n get<V>(atom: Atom<V>): Promise<V> {\n return store.resolve(atom);\n },\n set<V, A extends readonly unknown[]>(atom: WritableAtom<V, A>, ...args: A): Promise<void> {\n return store.set(atom, ...args);\n },\n invalidate(atom: Atom<unknown>): void {\n store.invalidate(atom);\n },\n invalidateMany(atoms: ReadonlyArray<Atom<unknown>>): void {\n store.invalidateMany(atoms);\n },\n subscribe<V>(atom: Atom<V>, listener: (state: AtomState<V>) => void): () => void {\n return store.subscribe(atom, () => {\n listener(store.getSnapshot(atom));\n });\n },\n };\n return this.#client;\n }\n}\n\nexport function createStore(): Store {\n return new Store();\n}\n\nfunction isAbortError(e: unknown): boolean {\n return e instanceof DOMException && e.name === \"AbortError\";\n}\n\nfunction extractPreviousValue<V>(state: AtomState<V>): V | undefined {\n if (state.status === \"stale\" || state.status === \"fresh\") {\n return state.value;\n }\n if (state.status === \"error\") {\n return state.value;\n }\n return undefined;\n}\n"],"mappings":";AAAA,MAAa,SAAS,OAAO,eAAe;AAC5C,MAAa,WAAW,OAAO,iBAAiB;AAChD,MAAa,cAAc,OAAO,mBAAmB;;;AC8BrD,SAAgB,KAId,QAAoD;CACpD,MAAM,WAAsC,OAAO,OAAO,KAAK;AAC/D,UAAS,MAAM,OAAO;AAEtB,KAAI,OAAO,cAAc,KACvB,UAAS,aAAa,OAAO;AAE/B,KAAI,OAAO,gBAAgB,KACzB,UAAS,eAAe,OAAO;AAEjC,KAAI,OAAO,eAAe,KACxB,UAAS,cAAc,OAAO;AAEhC,KAAI,OAAO,OAAO,KAChB,UAAS,MAAM,OAAO;AAExB,KAAI,OAAO,WAAW,KACpB,UAAS,UAAU,OAAO;AAG5B,KAAI,OAAO,OAAO,KAChB,QAAO;GACJ,SAAS;GACT,WAAW,EAAE;EACd,YAAY,OAAO;EACpB;AAGH,QAAO;GACJ,SAAS;EACV,YAAY,OAAO;EACpB;;;;ACnCH,SAAgB,cAAc,QAA+C;AAC3E,QAAQ,OAA6D;;AAGvE,SAAgB,WAKd,SAAgF;CAChF,MAAM,cAAc,QAAQ,eAAe;CAC3C,MAAM,UAAU,QAAQ,WAAW;CACnC,MAAM,wBAAQ,IAAI,KAAyB;CAC3C,MAAM,WAAoB,EAAE;CAC5B,MAAM,iCAAiB,IAAI,KAAoC;CAE/D,MAAM,OAAmB;EACvB,eAAe,QAA6B;AAC1C,QAAK,MAAM,MAAM,eACf,IAAG,OAAO;;EAGd,cAAc,IAA+C;AAC3D,kBAAe,IAAI,GAAG;AACtB,gBAAa;AACX,mBAAe,OAAO,GAAG;;;EAG9B;CAED,SAAS,WAAW,QAA2B;AAC5C,SAAiD,eAAe;;CAGnE,SAAS,YAAY,OAA2B;EAC9C,MAAM,SAAS,MAAM,IAAI,MAAM;AAC/B,MAAI,UAAU,MAAM;A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