@kdeveloper/kvark 0.6.8 → 0.6.9
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/react/index.js +1 -1
- package/dist/react/index.js.map +1 -1
- package/package.json +1 -1
package/dist/react/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { jsx } from "react/jsx-runtime";
|
|
|
4
4
|
//#region src/react/provider.tsx
|
|
5
5
|
const StoreContext = createContext(null);
|
|
6
6
|
function Provider({ store, children }) {
|
|
7
|
-
return /* @__PURE__ */ jsx(StoreContext, {
|
|
7
|
+
return /* @__PURE__ */ jsx(StoreContext.Provider, {
|
|
8
8
|
value: store,
|
|
9
9
|
children
|
|
10
10
|
});
|
package/dist/react/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/react/provider.tsx","../../src/react/use-stable-fn.ts","../../src/react/use-atom-value.ts","../../src/react/use-set-atom.ts","../../src/react/use-atom.ts","../../src/react/use-atom-context.ts"],"sourcesContent":["import { createContext, useContext, type ReactNode } from \"react\";\nimport type { 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 { useCallback, useRef } from \"react\";\n\nexport function useStableFn<Args extends unknown[], R>(\n fn: (...args: Args) => R,\n): (...args: Args) => R {\n const ref = useRef(fn);\n ref.current = fn;\n\n return useCallback((...args: Args) => ref.current(...args), []);\n}\n","import { useSyncExternalStore } from \"react\";\nimport type { Atom, AtomState, StalePolicy } from \"@/internal/types.js\";\nimport { CONFIG } from \"@/internal/types.js\";\nimport { useStore } from \"@/react/provider.js\";\nimport { useStableFn } from \"@/react/use-stable-fn.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 subscribe = useStableFn((notify: () => void) => store.subscribe(atom, notify));\n const getSnapshot = useStableFn(() => store.getSnapshot(atom));\n const getServerSnapshot = useStableFn(() => store.getServerSnapshot(atom));\n\n const snapshot: AtomState<V> = useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\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 \"@/react/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 \"@/react/use-atom-value.js\";\nimport { useSetAtom } from \"@/react/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 \"@/react/provider.js\";\n\nexport function useAtomContext<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,
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/react/provider.tsx","../../src/react/use-stable-fn.ts","../../src/react/use-atom-value.ts","../../src/react/use-set-atom.ts","../../src/react/use-atom.ts","../../src/react/use-atom-context.ts"],"sourcesContent":["import { createContext, useContext, type ReactNode } from \"react\";\nimport type { 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.Provider value={store}>{children}</StoreContext.Provider>;\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 { useCallback, useRef } from \"react\";\n\nexport function useStableFn<Args extends unknown[], R>(\n fn: (...args: Args) => R,\n): (...args: Args) => R {\n const ref = useRef(fn);\n ref.current = fn;\n\n return useCallback((...args: Args) => ref.current(...args), []);\n}\n","import { useSyncExternalStore } from \"react\";\nimport type { Atom, AtomState, StalePolicy } from \"@/internal/types.js\";\nimport { CONFIG } from \"@/internal/types.js\";\nimport { useStore } from \"@/react/provider.js\";\nimport { useStableFn } from \"@/react/use-stable-fn.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 subscribe = useStableFn((notify: () => void) => store.subscribe(atom, notify));\n const getSnapshot = useStableFn(() => store.getSnapshot(atom));\n const getServerSnapshot = useStableFn(() => store.getServerSnapshot(atom));\n\n const snapshot: AtomState<V> = useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\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 \"@/react/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 \"@/react/use-atom-value.js\";\nimport { useSetAtom } from \"@/react/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 \"@/react/provider.js\";\n\nexport function useAtomContext<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,aAAa,UAAd;EAAuB,OAAO;EAAQ;EAAiC,CAAA;;AAGhF,SAAgB,WAAkB;CAChC,MAAM,QAAQ,WAAW,aAAa;AACtC,KAAI,SAAS,KACX,OAAM,IAAI,MAAM,4CAA4C;AAE9D,QAAO;;;;ACjBT,SAAgB,YACd,IACsB;CACtB,MAAM,MAAM,OAAO,GAAG;AACtB,KAAI,UAAU;AAEd,QAAO,aAAa,GAAG,SAAe,IAAI,QAAQ,GAAG,KAAK,EAAE,EAAE,CAAC;;;;ACMjE,SAAgB,aAAgB,MAAe,MAAgD;CAC7F,MAAM,QAAQ,UAAU;CAMxB,MAAM,WAAyB,qBAJb,aAAa,WAAuB,MAAM,UAAU,MAAM,OAAO,CAAC,EAChE,kBAAkB,MAAM,YAAY,KAAK,CAAC,EACpC,kBAAkB,MAAM,kBAAkB,KAAK,CAAC,CAEoB;CAE9F,MAAM,cAA2B,KAAK,QAAQ,eAAe;AAE7D,KAAI,SAAS,WAAW,UACtB,OAAM,MAAM,QAAQ,KAAK;AAG3B,KAAI,SAAS,WAAW,SAAS;AAC/B,MAAI,gBAAgB,UAClB,OAAM,MAAM,QAAQ,KAAK;AAGtB,QAAM,QAAQ,KAAK;AAExB,MAAI,MAAM,YAAY,KACpB,QAAO;GAAE,OAAO,SAAS;GAAO,SAAS;GAAM,OAAO,KAAA;GAAW;AAEnE,SAAO,SAAS;;AAGlB,KAAI,SAAS,WAAW,SAAS;AAC/B,MAAI,MAAM,YAAY,QAAQ,SAAS,UAAU,KAAA,EAC/C,QAAO;GACL,OAAO,SAAS;GAChB,SAAS;GACT,OAAO,SAAS;GACjB;AAEH,QAAM,SAAS;;AAIjB,KAAI,MAAM,YAAY,KACpB,QAAO;EAAE,OAAO,SAAS;EAAO,SAAS;EAAO,OAAO,KAAA;EAAW;AAEpE,QAAO,SAAS;;;;ACrDlB,SAAgB,WACd,MAC+B;CAC/B,MAAM,QAAQ,UAAU;AACxB,QAAO,aAAa,GAAG,SAA2B,MAAM,IAAI,MAAM,GAAG,KAAK,EAAE,CAAC,OAAO,KAAK,CAAC;;;;ACJ5F,SAAgB,QACd,MAC6C;AAG7C,QAAO,CAFO,aAAa,KAAK,EACjB,WAAW,KAAK,CACT;;;;ACLxB,SAAgB,eAAkB,UAA8D;CAC9F,MAAM,QAAQ,UAAU;AACxB,QAAO,kBAA8B,SAAS,MAAM,WAAW,CAAC,EAAE,CAAC,OAAO,SAAS,CAAC"}
|