@context-query/react 0.3.2-beta.4 → 0.4.0

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.
@@ -0,0 +1,7 @@
1
+ export { createUseContextAtom } from "./use-context-atom";
2
+ export { createUseContextAtomValue } from "./use-context-atom-value";
3
+ export { createUseContextSetAtom } from "./use-context-set-atom";
4
+ export { createUseStore } from "./use-store";
5
+ export { createUseAllAtoms } from "./use-all-atoms";
6
+ export { createUseAllAtomsValue } from "./use-all-atoms-value";
7
+ export { createUseUpdateAllAtoms } from "./use-update-all-atoms";
@@ -0,0 +1,2 @@
1
+ import { createStoreContext } from "../context";
2
+ export declare function createUseAllAtomsValue<TAtoms extends Record<string, any>>(StoreContext: ReturnType<typeof createStoreContext<TAtoms>>): () => TAtoms;
@@ -0,0 +1,2 @@
1
+ import { createStoreContext } from "../context";
2
+ export declare function createUseAllAtoms<TAtoms extends Record<string, any>>(StoreContext: ReturnType<typeof createStoreContext<TAtoms>>): () => [TAtoms, (newAtoms: Partial<TAtoms>) => void];
@@ -0,0 +1,2 @@
1
+ import { createStoreContext } from "../context";
2
+ export declare function createUseContextAtomValue<TAtoms extends Record<string, any>>(StoreContext: ReturnType<typeof createStoreContext<TAtoms>>): <TKey extends keyof TAtoms>(key: TKey) => TAtoms[TKey];
@@ -0,0 +1,2 @@
1
+ import { createStoreContext } from "../context";
2
+ export declare function createUseContextAtom<TAtoms extends Record<string, any>>(StoreContext: ReturnType<typeof createStoreContext<TAtoms>>): <TKey extends keyof TAtoms>(key: TKey) => readonly [TAtoms[TKey], (newValue: TAtoms[TKey] | ((prev: TAtoms[TKey]) => TAtoms[TKey])) => void];
@@ -0,0 +1,2 @@
1
+ import { createStoreContext } from "../context";
2
+ export declare function createUseContextSetAtom<TAtoms extends Record<string, any>>(StoreContext: ReturnType<typeof createStoreContext<TAtoms>>): <TKey extends keyof TAtoms>(key: TKey) => ((value: TAtoms[TKey] | ((prev: TAtoms[TKey]) => TAtoms[TKey])) => void);
@@ -0,0 +1,3 @@
1
+ import type { ContextQueryStore } from "@context-query/core";
2
+ import { createStoreContext } from "../context";
3
+ export declare function createUseStore<TAtoms extends Record<string, any>>(StoreContext: ReturnType<typeof createStoreContext<TAtoms>>): () => ContextQueryStore<TAtoms>;
@@ -0,0 +1,2 @@
1
+ import { createStoreContext } from "../context";
2
+ export declare function createUseUpdateAllAtoms<TAtoms extends Record<string, any>>(StoreContext: ReturnType<typeof createStoreContext<TAtoms>>): () => ((newAtoms: Partial<TAtoms>) => void);
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var t=require("react"),e=require("react/jsx-runtime");function r(e){return r=>{const s=(()=>{const r=t.useContext(e);if(!r)throw new Error("useContextAtom must be used within a ContextQueryProvider");return r})(),[o,u]=t.useState((()=>s.getAtomValue(r)));t.useEffect((()=>{u(s.getAtomValue(r))}),[s,r]),t.useEffect((()=>{const t=s.subscribeToAtom(r,((t,e)=>{u(e)}));return()=>{t.unsubscribe()}}),[r,s]);return[o,t.useCallback((t=>{const e=s.getAtomValue(r),o="function"==typeof t?t(e):t;s.setAtomValue(r,o)}),[r,s])]}}function s(e){return r=>{const s=(()=>{const r=t.useContext(e);if(!r)throw new Error("useContextAtomValue must be used within a ContextQueryProvider");return r})(),[o,u]=t.useState((()=>s.getAtomValue(r)));return t.useEffect((()=>{u(s.getAtomValue(r))}),[s,r]),t.useEffect((()=>{const t=s.subscribeToAtom(r,((t,e)=>{u(e)}));return()=>{t.unsubscribe()}}),[r,s]),o}}function o(e){return r=>{const s=(()=>{const r=t.useContext(e);if(!r)throw new Error("useContextSetAtom must be used within a ContextQueryProvider");return r})();return t.useCallback((t=>{const e=s.getAtomValue(r),o="function"==typeof t?t(e):t;s.setAtomValue(r,o)}),[r,s])}}function u(e){return()=>{const r=(()=>{const r=t.useContext(e);if(!r)throw new Error("useAllAtoms must be used within a ContextQueryProvider");return r})(),[s,o]=t.useState((()=>r.getAllAtomValues()));t.useEffect((()=>{o(r.getAllAtomValues())}),[r]),t.useEffect((()=>{const t=[],e=r.getAllAtomValues();return Object.keys(e).forEach((e=>{const s=r.subscribeToAtom(e,(()=>{o(r.getAllAtomValues())}));t.push(s)})),()=>{t.forEach((t=>t.unsubscribe()))}}),[r]);return[s,t.useCallback((t=>{r.updateAllAtoms(t)}),[r])]}}function n(e){return()=>{const r=(()=>{const r=t.useContext(e);if(!r)throw new Error("useAllAtomsValue must be used within a ContextQueryProvider");return r})(),[s,o]=t.useState((()=>r.getAllAtomValues()));return t.useEffect((()=>{o(r.getAllAtomValues())}),[r]),t.useEffect((()=>{const t=[],e=r.getAllAtomValues();return Object.keys(e).forEach((e=>{const s=r.subscribeToAtom(e,(()=>{o(r.getAllAtomValues())}));t.push(s)})),()=>{t.forEach((t=>t.unsubscribe()))}}),[r]),s}}function i(e){return()=>{const r=(()=>{const r=t.useContext(e);if(!r)throw new Error("useUpdateAllAtoms must be used within a ContextQueryProvider");return r})();return t.useCallback((t=>{r.updateAllAtoms(t)}),[r])}}class l{value;listeners;constructor(t){this.value=t,this.listeners=new Set}getValue(){return this.value}setValue(t){Object.is(this.value,t)||(this.value=t,this.notifyListeners())}notifyListeners(){this.listeners.forEach((t=>t(this.value)))}subscribe(t){return this.listeners.add(t),{unsubscribe:()=>{this.listeners.delete(t)}}}}class c{atoms;constructor(t){this.atoms=new Map,Object.entries(t).forEach((([t,e])=>{this.atoms.set(t,new l(e))}))}getAtomValue(t){const e=this.atoms.get(t);if(!e)throw new Error(`Atom with key "${String(t)}" not found`);return e.getValue()}setAtomValue(t,e){const r=this.atoms.get(t);if(!r)throw new Error(`Atom with key "${String(t)}" not found`);r.setValue(e)}subscribeToAtom(t,e){const r=this.atoms.get(t);if(!r)throw new Error(`Atom with key "${String(t)}" not found`);return r.subscribe((r=>{e(t,r)}))}getAllAtomValues(){const t={};return this.atoms.forEach(((e,r)=>{t[r]=e.getValue()})),t}updateAllAtoms(t){Object.entries(t).forEach((([t,e])=>{const r=this.atoms.get(t);r&&r.setValue(e)}))}}function a(){const r=t.createContext(null);return{ContextQueryProvider:function({children:s,atoms:o}){const u=t.useMemo((()=>new c(o)),[o]);return e.jsx(r.Provider,{value:u,children:s})},StoreContext:r}}exports.createContextQuery=function(){const{ContextQueryProvider:e,StoreContext:l}=a(),c=r(l),m=s(l),A=o(l),f=function(e){return()=>{const r=t.useContext(e);if(!r)throw new Error("useStore must be used within a ContextQueryProvider");return r}}(l);return{ContextQueryProvider:e,useContextAtom:c,useContextAtomValue:m,useContextSetAtom:A,useStore:f,useAllAtoms:u(l),useAllAtomsValue:n(l),useUpdateAllAtoms:i(l)}};
1
+ "use strict";var t=require("react"),e=require("react/jsx-runtime");function s(e){return()=>{const s=t.useContext(e);if(!s)throw new Error("Hook must be used within a ContextQueryProvider");return s}}function r(e,s){const r=t.useCallback(t=>{const r=e.subscribeToAtom(s,()=>{t()});return()=>r.unsubscribe()},[e,s]),u=t.useCallback(()=>e.getAtomValue(s),[e,s]);return t.useSyncExternalStore(r,u,u)}class u{value;listeners;constructor(t){this.value=t,this.listeners=new Set}getValue(){return this.value}setValue(t){Object.is(this.value,t)||(this.value=t,this.notifyListeners())}notifyListeners(){this.listeners.forEach(t=>t())}subscribe(t){return this.listeners.add(t),{unsubscribe:()=>{this.listeners.delete(t)}}}}class n{atoms;cachedAllValues=null;allValuesDirty=!0;constructor(t){this.atoms=new Map,Object.entries(t).forEach(([t,e])=>{const s=new u(e);this.atoms.set(t,s),s.subscribe(()=>{this.allValuesDirty=!0})})}getAtom(t){const e=this.atoms.get(t);if(!e)throw new Error(`Atom with key "${String(t)}" not found`);return e}getAtomValue(t){return this.getAtom(t).getValue()}setAtomValue(t,e){this.getAtom(t).setValue(e)}subscribeToAtom(t,e){return this.getAtom(t).subscribe(s=>{e(t,s)})}getAllAtomValues(){if(!this.allValuesDirty&&null!==this.cachedAllValues)return this.cachedAllValues;const t={};return this.atoms.forEach((e,s)=>{t[s]=e.getValue()}),this.cachedAllValues=t,this.allValuesDirty=!1,t}updateAllAtoms(t){Object.entries(t).forEach(([t,e])=>{const s=this.atoms.get(t);s&&s.setValue(e)})}subscribeAll(t){const e=[];return this.atoms.forEach(s=>{const r=s.subscribe(()=>{t(this.getAllAtomValues())});e.push(r)}),{unsubscribe:()=>{e.forEach(t=>t.unsubscribe())}}}}function o(){const s=t.createContext(null);return{ContextQueryProvider:function({children:r,atoms:u}){const o=t.useMemo(()=>new n(u),[u]);return e.jsx(s.Provider,{value:o,children:r})},StoreContext:s}}exports.createContextQuery=function(){const{ContextQueryProvider:e,StoreContext:u}=o(),n=function(e){const u=s(e);return e=>{const s=u();return[r(s,e),t.useCallback(t=>{const r=s.getAtomValue(e),u="function"==typeof t?t(r):t;s.setAtomValue(e,u)},[e,s])]}}(u),l=function(t){const e=s(t);return t=>r(e(),t)}(u),c=function(e){const r=s(e);return e=>{const s=r();return t.useCallback(t=>{const r=s.getAtomValue(e),u="function"==typeof t?t(r):t;s.setAtomValue(e,u)},[e,s])}}(u),a=function(t){const e=s(t);return()=>e()}(u),i=function(e){const r=s(e);return()=>{const e=r(),s=t.useCallback(t=>{const s=e.subscribeAll(()=>{t()});return()=>s.unsubscribe()},[e]),u=t.useCallback(()=>e.getAllAtomValues(),[e]);return[t.useSyncExternalStore(s,u,u),t.useCallback(t=>{e.updateAllAtoms(t)},[e])]}}(u),b=function(e){const r=s(e);return()=>{const e=r(),s=t.useCallback(t=>{const s=e.subscribeAll(()=>{t()});return()=>s.unsubscribe()},[e]),u=t.useCallback(()=>e.getAllAtomValues(),[e]);return t.useSyncExternalStore(s,u,u)}}(u),A=function(e){const r=s(e);return()=>{const e=r();return t.useCallback(t=>{e.updateAllAtoms(t)},[e])}}(u);return{ContextQueryProvider:e,useContextAtom:n,useContextAtomValue:l,useContextSetAtom:c,useStore:a,useAllAtoms:i,useAllAtomsValue:b,useUpdateAllAtoms:A}};
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/hooks.ts","../../../node_modules/.pnpm/@context-query+core@0.3.2-beta.1/node_modules/@context-query/core/dist/index.mjs","../src/provider.tsx","../src/context.ts","../src/index.ts"],"sourcesContent":["import type { ContextQueryStore } from \"@context-query/core\";\nimport { useCallback, useContext, useEffect, useState } from \"react\";\nimport { createStoreContext } from \"./context\";\n\nexport function createUseStore<TAtoms extends Record<string, any>>(\n StoreContext: ReturnType<typeof createStoreContext<TAtoms>>\n): () => ContextQueryStore<TAtoms> {\n return () => {\n const store = useContext(StoreContext);\n\n if (!store) {\n throw new Error(\"useStore must be used within a ContextQueryProvider\");\n }\n\n return store;\n };\n}\n\nexport function createUseContextAtom<TAtoms extends Record<string, any>>(\n StoreContext: ReturnType<typeof createStoreContext<TAtoms>>\n) {\n const useStore = () => {\n const store = useContext(StoreContext);\n\n if (!store) {\n throw new Error(\n \"useContextAtom must be used within a ContextQueryProvider\"\n );\n }\n\n return store;\n };\n\n return <TKey extends keyof TAtoms>(key: TKey) => {\n const store = useStore();\n const [value, setValue] = useState<TAtoms[TKey]>(() =>\n store.getAtomValue(key)\n );\n\n useEffect(() => {\n setValue(store.getAtomValue(key));\n }, [store, key]);\n\n useEffect(() => {\n const handleChange = (_: TKey, newValue: TAtoms[TKey]) => {\n setValue(newValue);\n };\n\n const subscription = store.subscribeToAtom(key, handleChange);\n\n return () => {\n subscription.unsubscribe();\n };\n }, [key, store]);\n\n const setAtom = useCallback(\n (newValue: TAtoms[TKey] | ((prev: TAtoms[TKey]) => TAtoms[TKey])) => {\n const currentValue = store.getAtomValue(key);\n const updatedValue =\n typeof newValue === \"function\"\n ? (newValue as Function)(currentValue)\n : newValue;\n\n store.setAtomValue(key, updatedValue);\n },\n [key, store]\n );\n\n return [value, setAtom] as const;\n };\n}\n\nexport function createUseContextAtomValue<TAtoms extends Record<string, any>>(\n StoreContext: ReturnType<typeof createStoreContext<TAtoms>>\n) {\n const useStore = () => {\n const store = useContext(StoreContext);\n\n if (!store) {\n throw new Error(\n \"useContextAtomValue must be used within a ContextQueryProvider\"\n );\n }\n\n return store;\n };\n\n return <TKey extends keyof TAtoms>(key: TKey): TAtoms[TKey] => {\n const store = useStore();\n const [value, setValue] = useState<TAtoms[TKey]>(() =>\n store.getAtomValue(key)\n );\n\n useEffect(() => {\n setValue(store.getAtomValue(key));\n }, [store, key]);\n\n useEffect(() => {\n const handleChange = (_: TKey, newValue: TAtoms[TKey]) => {\n setValue(newValue);\n };\n\n const subscription = store.subscribeToAtom(key, handleChange);\n\n return () => {\n subscription.unsubscribe();\n };\n }, [key, store]);\n\n return value;\n };\n}\n\nexport function createUseContextSetAtom<TAtoms extends Record<string, any>>(\n StoreContext: ReturnType<typeof createStoreContext<TAtoms>>\n) {\n const useStore = () => {\n const store = useContext(StoreContext);\n\n if (!store) {\n throw new Error(\n \"useContextSetAtom must be used within a ContextQueryProvider\"\n );\n }\n\n return store;\n };\n\n return <TKey extends keyof TAtoms>(\n key: TKey\n ): ((\n value: TAtoms[TKey] | ((prev: TAtoms[TKey]) => TAtoms[TKey])\n ) => void) => {\n const store = useStore();\n\n return useCallback(\n (newValue: TAtoms[TKey] | ((prev: TAtoms[TKey]) => TAtoms[TKey])) => {\n const currentValue = store.getAtomValue(key);\n const updatedValue =\n typeof newValue === \"function\"\n ? (newValue as Function)(currentValue)\n : newValue;\n\n store.setAtomValue(key, updatedValue);\n },\n [key, store]\n );\n };\n}\n\nexport function createUseAllAtoms<TAtoms extends Record<string, any>>(\n StoreContext: ReturnType<typeof createStoreContext<TAtoms>>\n) {\n const useStore = () => {\n const store = useContext(StoreContext);\n\n if (!store) {\n throw new Error(\"useAllAtoms must be used within a ContextQueryProvider\");\n }\n\n return store;\n };\n\n return (): [TAtoms, (newAtoms: Partial<TAtoms>) => void] => {\n const store = useStore();\n const [allValues, setAllValues] = useState<TAtoms>(() =>\n store.getAllAtomValues()\n );\n\n useEffect(() => {\n setAllValues(store.getAllAtomValues());\n }, [store]);\n\n useEffect(() => {\n const subscriptions: Array<{ unsubscribe: () => void }> = [];\n const currentAtoms = store.getAllAtomValues();\n\n Object.keys(currentAtoms).forEach((key) => {\n const subscription = store.subscribeToAtom(key as keyof TAtoms, () => {\n setAllValues(store.getAllAtomValues());\n });\n subscriptions.push(subscription);\n });\n\n return () => {\n subscriptions.forEach((sub) => sub.unsubscribe());\n };\n }, [store]);\n\n const updateAllAtoms = useCallback(\n (newAtoms: Partial<TAtoms>) => {\n store.updateAllAtoms(newAtoms);\n },\n [store]\n );\n\n return [allValues, updateAllAtoms] as const;\n };\n}\n\nexport function createUseAllAtomsValue<TAtoms extends Record<string, any>>(\n StoreContext: ReturnType<typeof createStoreContext<TAtoms>>\n) {\n const useStore = () => {\n const store = useContext(StoreContext);\n\n if (!store) {\n throw new Error(\n \"useAllAtomsValue must be used within a ContextQueryProvider\"\n );\n }\n\n return store;\n };\n\n return (): TAtoms => {\n const store = useStore();\n const [allValues, setAllValues] = useState<TAtoms>(() =>\n store.getAllAtomValues()\n );\n\n useEffect(() => {\n setAllValues(store.getAllAtomValues());\n }, [store]);\n\n useEffect(() => {\n const subscriptions: Array<{ unsubscribe: () => void }> = [];\n const currentAtoms = store.getAllAtomValues();\n\n Object.keys(currentAtoms).forEach((key) => {\n const subscription = store.subscribeToAtom(key as keyof TAtoms, () => {\n setAllValues(store.getAllAtomValues());\n });\n subscriptions.push(subscription);\n });\n\n return () => {\n subscriptions.forEach((sub) => sub.unsubscribe());\n };\n }, [store]);\n\n return allValues;\n };\n}\n\nexport function createUseUpdateAllAtoms<TAtoms extends Record<string, any>>(\n StoreContext: ReturnType<typeof createStoreContext<TAtoms>>\n) {\n const useStore = () => {\n const store = useContext(StoreContext);\n\n if (!store) {\n throw new Error(\n \"useUpdateAllAtoms must be used within a ContextQueryProvider\"\n );\n }\n\n return store;\n };\n\n return (): ((newAtoms: Partial<TAtoms>) => void) => {\n const store = useStore();\n\n return useCallback(\n (newAtoms: Partial<TAtoms>) => {\n store.updateAllAtoms(newAtoms);\n },\n [store]\n );\n };\n}\n","class t{value;listeners;constructor(t){this.value=t,this.listeners=new Set}getValue(){return this.value}setValue(t){Object.is(this.value,t)||(this.value=t,this.notifyListeners())}notifyListeners(){this.listeners.forEach((t=>t(this.value)))}subscribe(t){this.listeners.add(t);return{unsubscribe:()=>{this.listeners.delete(t)}}}}class e{atoms;constructor(e){this.atoms=new Map,Object.entries(e).forEach((([e,s])=>{this.atoms.set(e,new t(s))}))}getAtomValue(t){const e=this.atoms.get(t);if(!e)throw new Error(`Atom with key \"${String(t)}\" not found`);return e.getValue()}setAtomValue(t,e){const s=this.atoms.get(t);if(!s)throw new Error(`Atom with key \"${String(t)}\" not found`);s.setValue(e)}subscribeToAtom(t,e){const s=this.atoms.get(t);if(!s)throw new Error(`Atom with key \"${String(t)}\" not found`);return s.subscribe((s=>{e(t,s)}))}getAllAtomValues(){const t={};return this.atoms.forEach(((e,s)=>{t[s]=e.getValue()})),t}updateAllAtoms(t){Object.entries(t).forEach((([t,e])=>{const s=this.atoms.get(t);s&&s.setValue(e)}))}}export{t as AtomStore,e as ContextQueryStore};\n//# sourceMappingURL=index.mjs.map\n","import { ContextQueryStore } from \"@context-query/core\";\nimport { PropsWithChildren, useMemo } from \"react\";\nimport { createStoreContext } from \"./context\";\n\ntype AtomValues<T extends Record<string, any>> = {\n [K in keyof T]: T[K];\n};\n\nexport function createReactContextQuery<TAtoms extends Record<string, any>>() {\n const StoreContext = createStoreContext<TAtoms>();\n \n const ContextQueryProvider = function ContextQueryProvider({\n children,\n atoms,\n }: PropsWithChildren<{ atoms: AtomValues<TAtoms> }>) {\n const store = useMemo(\n () => new ContextQueryStore<TAtoms>(atoms),\n [atoms]\n );\n\n return (\n <StoreContext.Provider value={store}>{children}</StoreContext.Provider>\n );\n };\n\n return {\n ContextQueryProvider,\n StoreContext,\n };\n}\n","import type { ContextQueryStore } from \"@context-query/core\";\nimport { createContext } from \"react\";\n\nexport const createStoreContext = <TAtoms extends Record<string, any>>() => {\n return createContext<ContextQueryStore<TAtoms> | null>(null);\n};\n","import { \n createUseContextAtom, \n createUseContextAtomValue, \n createUseContextSetAtom,\n createUseStore,\n createUseAllAtoms,\n createUseAllAtomsValue,\n createUseUpdateAllAtoms\n} from \"./hooks\";\nimport { createReactContextQuery } from \"./provider\";\n\nexport function createContextQuery<TAtoms extends Record<string, any>>() {\n const { ContextQueryProvider, StoreContext } =\n createReactContextQuery<TAtoms>();\n \n const useContextAtom = createUseContextAtom<TAtoms>(StoreContext);\n const useContextAtomValue = createUseContextAtomValue<TAtoms>(StoreContext);\n const useContextSetAtom = createUseContextSetAtom<TAtoms>(StoreContext);\n const useStore = createUseStore<TAtoms>(StoreContext);\n const useAllAtoms = createUseAllAtoms<TAtoms>(StoreContext);\n const useAllAtomsValue = createUseAllAtomsValue<TAtoms>(StoreContext);\n const useUpdateAllAtoms = createUseUpdateAllAtoms<TAtoms>(StoreContext);\n \n return {\n ContextQueryProvider,\n useContextAtom,\n useContextAtomValue,\n useContextSetAtom,\n useStore,\n useAllAtoms,\n useAllAtomsValue,\n useUpdateAllAtoms,\n };\n}\n"],"names":["createUseContextAtom","StoreContext","key","store","useContext","Error","useStore","value","setValue","useState","getAtomValue","useEffect","subscription","subscribeToAtom","_","newValue","unsubscribe","useCallback","currentValue","updatedValue","setAtomValue","createUseContextAtomValue","createUseContextSetAtom","createUseAllAtoms","allValues","setAllValues","getAllAtomValues","subscriptions","currentAtoms","Object","keys","forEach","push","sub","newAtoms","updateAllAtoms","createUseAllAtomsValue","createUseUpdateAllAtoms","t","listeners","constructor","this","Set","getValue","is","notifyListeners","subscribe","add","delete","e","atoms","Map","entries","s","set","get","String","createReactContextQuery","createContext","ContextQueryProvider","children","useMemo","ContextQueryStore","_jsx","jsx","Provider","useContextAtom","useContextAtomValue","useContextSetAtom","createUseStore","useAllAtoms","useAllAtomsValue","useUpdateAllAtoms"],"mappings":"mEAkBM,SAAUA,EACdC,GAcA,OAAmCC,IACjC,MAAMC,EAbS,MACf,MAAMA,EAAQC,EAAUA,WAACH,GAEzB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","x_google_ignoreList":[1]}
1
+ {"version":3,"file":"index.cjs","sources":["../src/use-store-context.ts","../src/use-atom-subscription.ts","../../core/dist/index.mjs","../src/provider.tsx","../src/context.ts","../src/index.ts","../src/hooks/use-context-atom.ts","../src/hooks/use-context-atom-value.ts","../src/hooks/use-context-set-atom.ts","../src/hooks/use-store.ts","../src/hooks/use-all-atoms.ts","../src/hooks/use-all-atoms-value.ts","../src/hooks/use-update-all-atoms.ts"],"sourcesContent":["import type { ContextQueryStore } from \"@context-query/core\";\nimport { useContext } from \"react\";\nimport { createStoreContext } from \"./context\";\n\nexport function createUseStoreContext<TAtoms extends Record<string, any>>(\n StoreContext: ReturnType<typeof createStoreContext<TAtoms>>\n): () => ContextQueryStore<TAtoms> {\n return (): ContextQueryStore<TAtoms> => {\n const store = useContext(StoreContext);\n\n if (!store) {\n throw new Error(\"Hook must be used within a ContextQueryProvider\");\n }\n\n return store;\n };\n}\n","import type { ContextQueryStore } from \"@context-query/core\";\nimport { useCallback, useSyncExternalStore } from \"react\";\n\nexport function useAtomSubscription<\n TAtoms extends Record<string, any>,\n TKey extends keyof TAtoms,\n>(store: ContextQueryStore<TAtoms>, key: TKey): TAtoms[TKey] {\n const subscribe = useCallback(\n (callback: () => void) => {\n const subscription = store.subscribeToAtom(key, () => {\n callback();\n });\n return () => subscription.unsubscribe();\n },\n [store, key]\n );\n\n const getSnapshot = useCallback(\n () => store.getAtomValue(key),\n [store, key]\n );\n\n return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n}\n","class t{value;listeners;constructor(t){this.value=t,this.listeners=new Set}getValue(){return this.value}setValue(t){Object.is(this.value,t)||(this.value=t,this.notifyListeners())}notifyListeners(){this.listeners.forEach(t=>t())}subscribe(t){this.listeners.add(t);return{unsubscribe:()=>{this.listeners.delete(t)}}}}class s{atoms;cachedAllValues=null;allValuesDirty=!0;constructor(s){this.atoms=new Map,Object.entries(s).forEach(([s,e])=>{const l=new t(e);this.atoms.set(s,l),l.subscribe(()=>{this.allValuesDirty=!0})})}getAtom(t){const s=this.atoms.get(t);if(!s)throw new Error(`Atom with key \"${String(t)}\" not found`);return s}getAtomValue(t){return this.getAtom(t).getValue()}setAtomValue(t,s){this.getAtom(t).setValue(s)}subscribeToAtom(t,s){return this.getAtom(t).subscribe(e=>{s(t,e)})}getAllAtomValues(){if(!this.allValuesDirty&&null!==this.cachedAllValues)return this.cachedAllValues;const t={};return this.atoms.forEach((s,e)=>{t[e]=s.getValue()}),this.cachedAllValues=t,this.allValuesDirty=!1,t}updateAllAtoms(t){Object.entries(t).forEach(([t,s])=>{const e=this.atoms.get(t);e&&e.setValue(s)})}subscribeAll(t){const s=[];return this.atoms.forEach(e=>{const l=e.subscribe(()=>{t(this.getAllAtomValues())});s.push(l)}),{unsubscribe:()=>{s.forEach(t=>t.unsubscribe())}}}}export{t as AtomStore,s as ContextQueryStore};\n//# sourceMappingURL=index.mjs.map\n","import { ContextQueryStore } from \"@context-query/core\";\nimport { PropsWithChildren, useMemo } from \"react\";\nimport { createStoreContext } from \"./context\";\n\ntype AtomValues<T extends Record<string, any>> = {\n [K in keyof T]: T[K];\n};\n\nexport function createReactContextQuery<TAtoms extends Record<string, any>>() {\n const StoreContext = createStoreContext<TAtoms>();\n \n const ContextQueryProvider = function ContextQueryProvider({\n children,\n atoms,\n }: PropsWithChildren<{ atoms: AtomValues<TAtoms> }>) {\n const store = useMemo(\n () => new ContextQueryStore<TAtoms>(atoms),\n [atoms]\n );\n\n return (\n <StoreContext.Provider value={store}>{children}</StoreContext.Provider>\n );\n };\n\n return {\n ContextQueryProvider,\n StoreContext,\n };\n}\n","import type { ContextQueryStore } from \"@context-query/core\";\nimport { createContext } from \"react\";\n\nexport const createStoreContext = <TAtoms extends Record<string, any>>() => {\n return createContext<ContextQueryStore<TAtoms> | null>(null);\n};\n","import {\n createUseContextAtom,\n createUseContextAtomValue,\n createUseContextSetAtom,\n createUseStore,\n createUseAllAtoms,\n createUseAllAtomsValue,\n createUseUpdateAllAtoms\n} from \"./hooks\";\nimport { createReactContextQuery } from \"./provider\";\n\nexport function createContextQuery<TAtoms extends Record<string, any>>() {\n const { ContextQueryProvider, StoreContext } =\n createReactContextQuery<TAtoms>();\n\n const useContextAtom = createUseContextAtom<TAtoms>(StoreContext);\n const useContextAtomValue = createUseContextAtomValue<TAtoms>(StoreContext);\n const useContextSetAtom = createUseContextSetAtom<TAtoms>(StoreContext);\n const useStore = createUseStore<TAtoms>(StoreContext);\n const useAllAtoms = createUseAllAtoms<TAtoms>(StoreContext);\n const useAllAtomsValue = createUseAllAtomsValue<TAtoms>(StoreContext);\n const useUpdateAllAtoms = createUseUpdateAllAtoms<TAtoms>(StoreContext);\n\n return {\n ContextQueryProvider,\n useContextAtom,\n useContextAtomValue,\n useContextSetAtom,\n useStore,\n useAllAtoms,\n useAllAtomsValue,\n useUpdateAllAtoms,\n };\n}\n","import type { ContextQueryStore } from \"@context-query/core\";\nimport { useCallback } from \"react\";\nimport { createStoreContext } from \"../context\";\nimport { createUseStoreContext } from \"../use-store-context\";\nimport { useAtomSubscription } from \"../use-atom-subscription\";\n\nexport function createUseContextAtom<TAtoms extends Record<string, any>>(\n StoreContext: ReturnType<typeof createStoreContext<TAtoms>>\n) {\n const useStoreContext = createUseStoreContext<TAtoms>(StoreContext);\n\n return <TKey extends keyof TAtoms>(key: TKey) => {\n const store = useStoreContext();\n const value = useAtomSubscription(store, key);\n\n const setAtom = useCallback(\n (newValue: TAtoms[TKey] | ((prev: TAtoms[TKey]) => TAtoms[TKey])) => {\n const currentValue = store.getAtomValue(key);\n const updatedValue =\n typeof newValue === \"function\"\n ? (newValue as Function)(currentValue)\n : newValue;\n\n store.setAtomValue(key, updatedValue);\n },\n [key, store]\n );\n\n return [value, setAtom] as const;\n };\n}\n","import { createStoreContext } from \"../context\";\nimport { createUseStoreContext } from \"../use-store-context\";\nimport { useAtomSubscription } from \"../use-atom-subscription\";\n\nexport function createUseContextAtomValue<TAtoms extends Record<string, any>>(\n StoreContext: ReturnType<typeof createStoreContext<TAtoms>>\n) {\n const useStoreContext = createUseStoreContext<TAtoms>(StoreContext);\n\n return <TKey extends keyof TAtoms>(key: TKey): TAtoms[TKey] => {\n const store = useStoreContext();\n return useAtomSubscription(store, key);\n };\n}\n","import { useCallback } from \"react\";\nimport { createStoreContext } from \"../context\";\nimport { createUseStoreContext } from \"../use-store-context\";\n\nexport function createUseContextSetAtom<TAtoms extends Record<string, any>>(\n StoreContext: ReturnType<typeof createStoreContext<TAtoms>>\n) {\n const useStoreContext = createUseStoreContext<TAtoms>(StoreContext);\n\n return <TKey extends keyof TAtoms>(\n key: TKey\n ): ((\n value: TAtoms[TKey] | ((prev: TAtoms[TKey]) => TAtoms[TKey])\n ) => void) => {\n const store = useStoreContext();\n\n return useCallback(\n (newValue: TAtoms[TKey] | ((prev: TAtoms[TKey]) => TAtoms[TKey])) => {\n const currentValue = store.getAtomValue(key);\n const updatedValue =\n typeof newValue === \"function\"\n ? (newValue as Function)(currentValue)\n : newValue;\n\n store.setAtomValue(key, updatedValue);\n },\n [key, store]\n );\n };\n}\n","import type { ContextQueryStore } from \"@context-query/core\";\nimport { createStoreContext } from \"../context\";\nimport { createUseStoreContext } from \"../use-store-context\";\n\nexport function createUseStore<TAtoms extends Record<string, any>>(\n StoreContext: ReturnType<typeof createStoreContext<TAtoms>>\n): () => ContextQueryStore<TAtoms> {\n const useStoreContext = createUseStoreContext<TAtoms>(StoreContext);\n\n return () => {\n return useStoreContext();\n };\n}\n","import { useCallback, useSyncExternalStore } from \"react\";\nimport { createStoreContext } from \"../context\";\nimport { createUseStoreContext } from \"../use-store-context\";\n\nexport function createUseAllAtoms<TAtoms extends Record<string, any>>(\n StoreContext: ReturnType<typeof createStoreContext<TAtoms>>\n) {\n const useStoreContext = createUseStoreContext<TAtoms>(StoreContext);\n\n return (): [TAtoms, (newAtoms: Partial<TAtoms>) => void] => {\n const store = useStoreContext();\n\n const subscribe = useCallback(\n (callback: () => void) => {\n const subscription = store.subscribeAll(() => {\n callback();\n });\n return () => subscription.unsubscribe();\n },\n [store]\n );\n\n const getSnapshot = useCallback(\n () => store.getAllAtomValues(),\n [store]\n );\n\n const allValues = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n\n const updateAllAtoms = useCallback(\n (newAtoms: Partial<TAtoms>) => {\n store.updateAllAtoms(newAtoms);\n },\n [store]\n );\n\n return [allValues, updateAllAtoms] as const;\n };\n}\n","import { useCallback, useSyncExternalStore } from \"react\";\nimport { createStoreContext } from \"../context\";\nimport { createUseStoreContext } from \"../use-store-context\";\n\nexport function createUseAllAtomsValue<TAtoms extends Record<string, any>>(\n StoreContext: ReturnType<typeof createStoreContext<TAtoms>>\n) {\n const useStoreContext = createUseStoreContext<TAtoms>(StoreContext);\n\n return (): TAtoms => {\n const store = useStoreContext();\n\n const subscribe = useCallback(\n (callback: () => void) => {\n const subscription = store.subscribeAll(() => {\n callback();\n });\n return () => subscription.unsubscribe();\n },\n [store]\n );\n\n const getSnapshot = useCallback(\n () => store.getAllAtomValues(),\n [store]\n );\n\n return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n };\n}\n","import { useCallback } from \"react\";\nimport { createStoreContext } from \"../context\";\nimport { createUseStoreContext } from \"../use-store-context\";\n\nexport function createUseUpdateAllAtoms<TAtoms extends Record<string, any>>(\n StoreContext: ReturnType<typeof createStoreContext<TAtoms>>\n) {\n const useStoreContext = createUseStoreContext<TAtoms>(StoreContext);\n\n return (): ((newAtoms: Partial<TAtoms>) => void) => {\n const store = useStoreContext();\n\n return useCallback(\n (newAtoms: Partial<TAtoms>) => {\n store.updateAllAtoms(newAtoms);\n },\n [store]\n );\n };\n}\n"],"names":["createUseStoreContext","StoreContext","store","useContext","Error","useAtomSubscription","key","subscribe","useCallback","callback","subscription","subscribeToAtom","unsubscribe","getSnapshot","getAtomValue","useSyncExternalStore","t","value","listeners","constructor","this","Set","getValue","setValue","Object","is","notifyListeners","forEach","add","delete","s","atoms","cachedAllValues","allValuesDirty","Map","entries","e","l","set","getAtom","get","String","setAtomValue","getAllAtomValues","updateAllAtoms","subscribeAll","push","createReactContextQuery","createContext","ContextQueryProvider","children","useMemo","ContextQueryStore","_jsx","Provider","useContextAtom","useStoreContext","newValue","currentValue","updatedValue","createUseContextAtom","useContextAtomValue","createUseContextAtomValue","useContextSetAtom","createUseContextSetAtom","useStore","createUseStore","useAllAtoms","newAtoms","createUseAllAtoms","useAllAtomsValue","createUseAllAtomsValue","useUpdateAllAtoms","createUseUpdateAllAtoms"],"mappings":"mEAIM,SAAUA,EACdC,GAEA,MAAO,KACL,MAAMC,EAAQC,EAAAA,WAAWF,GAEzB,IAAKC,EACH,MAAM,IAAIE,MAAM,mDAGlB,OAAOF,EAEX,CCbM,SAAUG,EAGdH,EAAkCI,GAClC,MAAMC,EAAYC,cACfC,IACC,MAAMC,EAAeR,EAAMS,gBAAgBL,EAAK,KAC9CG,MAEF,MAAO,IAAMC,EAAaE,eAE5B,CAACV,EAAOI,IAGJO,EAAcL,cAClB,IAAMN,EAAMY,aAAaR,GACzB,CAACJ,EAAOI,IAGV,OAAOS,uBAAqBR,EAAWM,EAAaA,EACtD,CCvBA,MAAMG,EAAEC,MAAMC,UAAU,WAAAC,CAAYH,GAAGI,KAAKH,MAAMD,EAAEI,KAAKF,UAAU,IAAIG,GAAG,CAAC,QAAAC,GAAW,OAAOF,KAAKH,KAAK,CAAC,QAAAM,CAASP,GAAGQ,OAAOC,GAAGL,KAAKH,MAAMD,KAAKI,KAAKH,MAAMD,EAAEI,KAAKM,kBAAkB,CAAC,eAAAA,GAAkBN,KAAKF,UAAUS,QAAQX,GAAGA,IAAI,CAAC,SAAAT,CAAUS,GAAyB,OAAtBI,KAAKF,UAAUU,IAAIZ,GAAS,CAACJ,YAAY,KAAKQ,KAAKF,UAAUW,OAAOb,IAAI,EAAE,MAAMc,EAAEC,MAAMC,gBAAgB,KAAKC,gBAAe,EAAG,WAAAd,CAAYW,GAAGV,KAAKW,MAAM,IAAIG,IAAIV,OAAOW,QAAQL,G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AO,IAAMC,EAAaE,eAE5B,CAACV,IAGGW,EAAcL,EAAAA,YAClB,IAAMN,EAAMyC,mBACZ,CAACzC,IAYH,MAAO,CATWa,EAAAA,qBAAqBR,EAAWM,EAAaA,GAExCL,cACpB4D,IACClE,EAAM0C,eAAewB,IAEvB,CAAClE,KAKP,CLnBsBmE,CAA0BpE,GACxCqE,EMhBF,SACJrE,GAEA,MAAMuD,EAAkBxD,EAA8BC,GAEtD,MAAO,KACL,MAAMC,EAAQsD,IAERjD,EAAYC,cACfC,IACC,MAAMC,EAAeR,EAAM2C,aAAa,KACtCpC,MAEF,MAAO,IAAMC,EAAaE,eAE5B,CAACV,IAGGW,EAAcL,EAAAA,YAClB,IAAMN,EAAMyC,mBACZ,CAACzC,IAGH,OAAOa,uBAAqBR,EAAWM,EAAaA,GAExD,CNT2B0D,CAA+BtE,GAClDuE,EOjBF,SACJvE,GAEA,MAAMuD,EAAkBxD,EAA8BC,GAEtD,MAAO,KACL,MAAMC,EAAQsD,IAEd,OAAOhD,EAAAA,YACJ4D,IACClE,EAAM0C,eAAewB,IAEvB,CAAClE,IAGP,CPE4BuE,CAAgCxE,GAE1D,MAAO,CACLgD,uBACAM,iBACAM,sBACAE,oBACAE,WACAE,cACAG,mBACAE,oBAEJ"}
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import{useCallback as t,useState as e,useEffect as r,useContext as o,createContext as s,useMemo as n}from"react";import{jsx as u}from"react/jsx-runtime";function i(s){return n=>{const u=(()=>{const t=o(s);if(!t)throw new Error("useContextAtom must be used within a ContextQueryProvider");return t})(),[i,l]=e((()=>u.getAtomValue(n)));r((()=>{l(u.getAtomValue(n))}),[u,n]),r((()=>{const t=u.subscribeToAtom(n,((t,e)=>{l(e)}));return()=>{t.unsubscribe()}}),[n,u]);return[i,t((t=>{const e=u.getAtomValue(n),r="function"==typeof t?t(e):t;u.setAtomValue(n,r)}),[n,u])]}}function l(t){return s=>{const n=(()=>{const e=o(t);if(!e)throw new Error("useContextAtomValue must be used within a ContextQueryProvider");return e})(),[u,i]=e((()=>n.getAtomValue(s)));return r((()=>{i(n.getAtomValue(s))}),[n,s]),r((()=>{const t=n.subscribeToAtom(s,((t,e)=>{i(e)}));return()=>{t.unsubscribe()}}),[s,n]),u}}function c(e){return r=>{const s=(()=>{const t=o(e);if(!t)throw new Error("useContextSetAtom must be used within a ContextQueryProvider");return t})();return t((t=>{const e=s.getAtomValue(r),o="function"==typeof t?t(e):t;s.setAtomValue(r,o)}),[r,s])}}function a(s){return()=>{const n=(()=>{const t=o(s);if(!t)throw new Error("useAllAtoms must be used within a ContextQueryProvider");return t})(),[u,i]=e((()=>n.getAllAtomValues()));r((()=>{i(n.getAllAtomValues())}),[n]),r((()=>{const t=[],e=n.getAllAtomValues();return Object.keys(e).forEach((e=>{const r=n.subscribeToAtom(e,(()=>{i(n.getAllAtomValues())}));t.push(r)})),()=>{t.forEach((t=>t.unsubscribe()))}}),[n]);return[u,t((t=>{n.updateAllAtoms(t)}),[n])]}}function m(t){return()=>{const s=(()=>{const e=o(t);if(!e)throw new Error("useAllAtomsValue must be used within a ContextQueryProvider");return e})(),[n,u]=e((()=>s.getAllAtomValues()));return r((()=>{u(s.getAllAtomValues())}),[s]),r((()=>{const t=[],e=s.getAllAtomValues();return Object.keys(e).forEach((e=>{const r=s.subscribeToAtom(e,(()=>{u(s.getAllAtomValues())}));t.push(r)})),()=>{t.forEach((t=>t.unsubscribe()))}}),[s]),n}}function A(e){return()=>{const r=(()=>{const t=o(e);if(!t)throw new Error("useUpdateAllAtoms must be used within a ContextQueryProvider");return t})();return t((t=>{r.updateAllAtoms(t)}),[r])}}class h{value;listeners;constructor(t){this.value=t,this.listeners=new Set}getValue(){return this.value}setValue(t){Object.is(this.value,t)||(this.value=t,this.notifyListeners())}notifyListeners(){this.listeners.forEach((t=>t(this.value)))}subscribe(t){return this.listeners.add(t),{unsubscribe:()=>{this.listeners.delete(t)}}}}class f{atoms;constructor(t){this.atoms=new Map,Object.entries(t).forEach((([t,e])=>{this.atoms.set(t,new h(e))}))}getAtomValue(t){const e=this.atoms.get(t);if(!e)throw new Error(`Atom with key "${String(t)}" not found`);return e.getValue()}setAtomValue(t,e){const r=this.atoms.get(t);if(!r)throw new Error(`Atom with key "${String(t)}" not found`);r.setValue(e)}subscribeToAtom(t,e){const r=this.atoms.get(t);if(!r)throw new Error(`Atom with key "${String(t)}" not found`);return r.subscribe((r=>{e(t,r)}))}getAllAtomValues(){const t={};return this.atoms.forEach(((e,r)=>{t[r]=e.getValue()})),t}updateAllAtoms(t){Object.entries(t).forEach((([t,e])=>{const r=this.atoms.get(t);r&&r.setValue(e)}))}}function b(){const t=s(null);return{ContextQueryProvider:function({children:e,atoms:r}){const o=n((()=>new f(r)),[r]);return u(t.Provider,{value:o,children:e})},StoreContext:t}}function w(){const{ContextQueryProvider:t,StoreContext:e}=b(),r=i(e),s=l(e),n=c(e),u=function(t){return()=>{const e=o(t);if(!e)throw new Error("useStore must be used within a ContextQueryProvider");return e}}(e);return{ContextQueryProvider:t,useContextAtom:r,useContextAtomValue:s,useContextSetAtom:n,useStore:u,useAllAtoms:a(e),useAllAtomsValue:m(e),useUpdateAllAtoms:A(e)}}export{w as createContextQuery};
1
+ import{useContext as t,useCallback as e,useSyncExternalStore as s,createContext as r,useMemo as n}from"react";import{jsx as o}from"react/jsx-runtime";function u(e){return()=>{const s=t(e);if(!s)throw new Error("Hook must be used within a ContextQueryProvider");return s}}function l(t,r){const n=e(e=>{const s=t.subscribeToAtom(r,()=>{e()});return()=>s.unsubscribe()},[t,r]),o=e(()=>t.getAtomValue(r),[t,r]);return s(n,o,o)}class i{value;listeners;constructor(t){this.value=t,this.listeners=new Set}getValue(){return this.value}setValue(t){Object.is(this.value,t)||(this.value=t,this.notifyListeners())}notifyListeners(){this.listeners.forEach(t=>t())}subscribe(t){return this.listeners.add(t),{unsubscribe:()=>{this.listeners.delete(t)}}}}class c{atoms;cachedAllValues=null;allValuesDirty=!0;constructor(t){this.atoms=new Map,Object.entries(t).forEach(([t,e])=>{const s=new i(e);this.atoms.set(t,s),s.subscribe(()=>{this.allValuesDirty=!0})})}getAtom(t){const e=this.atoms.get(t);if(!e)throw new Error(`Atom with key "${String(t)}" not found`);return e}getAtomValue(t){return this.getAtom(t).getValue()}setAtomValue(t,e){this.getAtom(t).setValue(e)}subscribeToAtom(t,e){return this.getAtom(t).subscribe(s=>{e(t,s)})}getAllAtomValues(){if(!this.allValuesDirty&&null!==this.cachedAllValues)return this.cachedAllValues;const t={};return this.atoms.forEach((e,s)=>{t[s]=e.getValue()}),this.cachedAllValues=t,this.allValuesDirty=!1,t}updateAllAtoms(t){Object.entries(t).forEach(([t,e])=>{const s=this.atoms.get(t);s&&s.setValue(e)})}subscribeAll(t){const e=[];return this.atoms.forEach(s=>{const r=s.subscribe(()=>{t(this.getAllAtomValues())});e.push(r)}),{unsubscribe:()=>{e.forEach(t=>t.unsubscribe())}}}}function a(){const t=r(null);return{ContextQueryProvider:function({children:e,atoms:s}){const r=n(()=>new c(s),[s]);return o(t.Provider,{value:r,children:e})},StoreContext:t}}function A(){const{ContextQueryProvider:t,StoreContext:r}=a(),n=function(t){const s=u(t);return t=>{const r=s();return[l(r,t),e(e=>{const s=r.getAtomValue(t),n="function"==typeof e?e(s):e;r.setAtomValue(t,n)},[t,r])]}}(r),o=function(t){const e=u(t);return t=>l(e(),t)}(r),i=function(t){const s=u(t);return t=>{const r=s();return e(e=>{const s=r.getAtomValue(t),n="function"==typeof e?e(s):e;r.setAtomValue(t,n)},[t,r])}}(r),c=function(t){const e=u(t);return()=>e()}(r),A=function(t){const r=u(t);return()=>{const t=r(),n=e(e=>{const s=t.subscribeAll(()=>{e()});return()=>s.unsubscribe()},[t]),o=e(()=>t.getAllAtomValues(),[t]);return[s(n,o,o),e(e=>{t.updateAllAtoms(e)},[t])]}}(r),h=function(t){const r=u(t);return()=>{const t=r(),n=e(e=>{const s=t.subscribeAll(()=>{e()});return()=>s.unsubscribe()},[t]),o=e(()=>t.getAllAtomValues(),[t]);return s(n,o,o)}}(r),m=function(t){const s=u(t);return()=>{const t=s();return e(e=>{t.updateAllAtoms(e)},[t])}}(r);return{ContextQueryProvider:t,useContextAtom:n,useContextAtomValue:o,useContextSetAtom:i,useStore:c,useAllAtoms:A,useAllAtomsValue:h,useUpdateAllAtoms:m}}export{A as createContextQuery};
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../src/hooks.ts","../../../node_modules/.pnpm/@context-query+core@0.3.2-beta.1/node_modules/@context-query/core/dist/index.mjs","../src/provider.tsx","../src/context.ts","../src/index.ts"],"sourcesContent":["import type { ContextQueryStore } from \"@context-query/core\";\nimport { useCallback, useContext, useEffect, useState } from \"react\";\nimport { createStoreContext } from \"./context\";\n\nexport function createUseStore<TAtoms extends Record<string, any>>(\n StoreContext: ReturnType<typeof createStoreContext<TAtoms>>\n): () => ContextQueryStore<TAtoms> {\n return () => {\n const store = useContext(StoreContext);\n\n if (!store) {\n throw new Error(\"useStore must be used within a ContextQueryProvider\");\n }\n\n return store;\n };\n}\n\nexport function createUseContextAtom<TAtoms extends Record<string, any>>(\n StoreContext: ReturnType<typeof createStoreContext<TAtoms>>\n) {\n const useStore = () => {\n const store = useContext(StoreContext);\n\n if (!store) {\n throw new Error(\n \"useContextAtom must be used within a ContextQueryProvider\"\n );\n }\n\n return store;\n };\n\n return <TKey extends keyof TAtoms>(key: TKey) => {\n const store = useStore();\n const [value, setValue] = useState<TAtoms[TKey]>(() =>\n store.getAtomValue(key)\n );\n\n useEffect(() => {\n setValue(store.getAtomValue(key));\n }, [store, key]);\n\n useEffect(() => {\n const handleChange = (_: TKey, newValue: TAtoms[TKey]) => {\n setValue(newValue);\n };\n\n const subscription = store.subscribeToAtom(key, handleChange);\n\n return () => {\n subscription.unsubscribe();\n };\n }, [key, store]);\n\n const setAtom = useCallback(\n (newValue: TAtoms[TKey] | ((prev: TAtoms[TKey]) => TAtoms[TKey])) => {\n const currentValue = store.getAtomValue(key);\n const updatedValue =\n typeof newValue === \"function\"\n ? (newValue as Function)(currentValue)\n : newValue;\n\n store.setAtomValue(key, updatedValue);\n },\n [key, store]\n );\n\n return [value, setAtom] as const;\n };\n}\n\nexport function createUseContextAtomValue<TAtoms extends Record<string, any>>(\n StoreContext: ReturnType<typeof createStoreContext<TAtoms>>\n) {\n const useStore = () => {\n const store = useContext(StoreContext);\n\n if (!store) {\n throw new Error(\n \"useContextAtomValue must be used within a ContextQueryProvider\"\n );\n }\n\n return store;\n };\n\n return <TKey extends keyof TAtoms>(key: TKey): TAtoms[TKey] => {\n const store = useStore();\n const [value, setValue] = useState<TAtoms[TKey]>(() =>\n store.getAtomValue(key)\n );\n\n useEffect(() => {\n setValue(store.getAtomValue(key));\n }, [store, key]);\n\n useEffect(() => {\n const handleChange = (_: TKey, newValue: TAtoms[TKey]) => {\n setValue(newValue);\n };\n\n const subscription = store.subscribeToAtom(key, handleChange);\n\n return () => {\n subscription.unsubscribe();\n };\n }, [key, store]);\n\n return value;\n };\n}\n\nexport function createUseContextSetAtom<TAtoms extends Record<string, any>>(\n StoreContext: ReturnType<typeof createStoreContext<TAtoms>>\n) {\n const useStore = () => {\n const store = useContext(StoreContext);\n\n if (!store) {\n throw new Error(\n \"useContextSetAtom must be used within a ContextQueryProvider\"\n );\n }\n\n return store;\n };\n\n return <TKey extends keyof TAtoms>(\n key: TKey\n ): ((\n value: TAtoms[TKey] | ((prev: TAtoms[TKey]) => TAtoms[TKey])\n ) => void) => {\n const store = useStore();\n\n return useCallback(\n (newValue: TAtoms[TKey] | ((prev: TAtoms[TKey]) => TAtoms[TKey])) => {\n const currentValue = store.getAtomValue(key);\n const updatedValue =\n typeof newValue === \"function\"\n ? (newValue as Function)(currentValue)\n : newValue;\n\n store.setAtomValue(key, updatedValue);\n },\n [key, store]\n );\n };\n}\n\nexport function createUseAllAtoms<TAtoms extends Record<string, any>>(\n StoreContext: ReturnType<typeof createStoreContext<TAtoms>>\n) {\n const useStore = () => {\n const store = useContext(StoreContext);\n\n if (!store) {\n throw new Error(\"useAllAtoms must be used within a ContextQueryProvider\");\n }\n\n return store;\n };\n\n return (): [TAtoms, (newAtoms: Partial<TAtoms>) => void] => {\n const store = useStore();\n const [allValues, setAllValues] = useState<TAtoms>(() =>\n store.getAllAtomValues()\n );\n\n useEffect(() => {\n setAllValues(store.getAllAtomValues());\n }, [store]);\n\n useEffect(() => {\n const subscriptions: Array<{ unsubscribe: () => void }> = [];\n const currentAtoms = store.getAllAtomValues();\n\n Object.keys(currentAtoms).forEach((key) => {\n const subscription = store.subscribeToAtom(key as keyof TAtoms, () => {\n setAllValues(store.getAllAtomValues());\n });\n subscriptions.push(subscription);\n });\n\n return () => {\n subscriptions.forEach((sub) => sub.unsubscribe());\n };\n }, [store]);\n\n const updateAllAtoms = useCallback(\n (newAtoms: Partial<TAtoms>) => {\n store.updateAllAtoms(newAtoms);\n },\n [store]\n );\n\n return [allValues, updateAllAtoms] as const;\n };\n}\n\nexport function createUseAllAtomsValue<TAtoms extends Record<string, any>>(\n StoreContext: ReturnType<typeof createStoreContext<TAtoms>>\n) {\n const useStore = () => {\n const store = useContext(StoreContext);\n\n if (!store) {\n throw new Error(\n \"useAllAtomsValue must be used within a ContextQueryProvider\"\n );\n }\n\n return store;\n };\n\n return (): TAtoms => {\n const store = useStore();\n const [allValues, setAllValues] = useState<TAtoms>(() =>\n store.getAllAtomValues()\n );\n\n useEffect(() => {\n setAllValues(store.getAllAtomValues());\n }, [store]);\n\n useEffect(() => {\n const subscriptions: Array<{ unsubscribe: () => void }> = [];\n const currentAtoms = store.getAllAtomValues();\n\n Object.keys(currentAtoms).forEach((key) => {\n const subscription = store.subscribeToAtom(key as keyof TAtoms, () => {\n setAllValues(store.getAllAtomValues());\n });\n subscriptions.push(subscription);\n });\n\n return () => {\n subscriptions.forEach((sub) => sub.unsubscribe());\n };\n }, [store]);\n\n return allValues;\n };\n}\n\nexport function createUseUpdateAllAtoms<TAtoms extends Record<string, any>>(\n StoreContext: ReturnType<typeof createStoreContext<TAtoms>>\n) {\n const useStore = () => {\n const store = useContext(StoreContext);\n\n if (!store) {\n throw new Error(\n \"useUpdateAllAtoms must be used within a ContextQueryProvider\"\n );\n }\n\n return store;\n };\n\n return (): ((newAtoms: Partial<TAtoms>) => void) => {\n const store = useStore();\n\n return useCallback(\n (newAtoms: Partial<TAtoms>) => {\n store.updateAllAtoms(newAtoms);\n },\n [store]\n );\n };\n}\n","class t{value;listeners;constructor(t){this.value=t,this.listeners=new Set}getValue(){return this.value}setValue(t){Object.is(this.value,t)||(this.value=t,this.notifyListeners())}notifyListeners(){this.listeners.forEach((t=>t(this.value)))}subscribe(t){this.listeners.add(t);return{unsubscribe:()=>{this.listeners.delete(t)}}}}class e{atoms;constructor(e){this.atoms=new Map,Object.entries(e).forEach((([e,s])=>{this.atoms.set(e,new t(s))}))}getAtomValue(t){const e=this.atoms.get(t);if(!e)throw new Error(`Atom with key \"${String(t)}\" not found`);return e.getValue()}setAtomValue(t,e){const s=this.atoms.get(t);if(!s)throw new Error(`Atom with key \"${String(t)}\" not found`);s.setValue(e)}subscribeToAtom(t,e){const s=this.atoms.get(t);if(!s)throw new Error(`Atom with key \"${String(t)}\" not found`);return s.subscribe((s=>{e(t,s)}))}getAllAtomValues(){const t={};return this.atoms.forEach(((e,s)=>{t[s]=e.getValue()})),t}updateAllAtoms(t){Object.entries(t).forEach((([t,e])=>{const s=this.atoms.get(t);s&&s.setValue(e)}))}}export{t as AtomStore,e as ContextQueryStore};\n//# sourceMappingURL=index.mjs.map\n","import { ContextQueryStore } from \"@context-query/core\";\nimport { PropsWithChildren, useMemo } from \"react\";\nimport { createStoreContext } from \"./context\";\n\ntype AtomValues<T extends Record<string, any>> = {\n [K in keyof T]: T[K];\n};\n\nexport function createReactContextQuery<TAtoms extends Record<string, any>>() {\n const StoreContext = createStoreContext<TAtoms>();\n \n const ContextQueryProvider = function ContextQueryProvider({\n children,\n atoms,\n }: PropsWithChildren<{ atoms: AtomValues<TAtoms> }>) {\n const store = useMemo(\n () => new ContextQueryStore<TAtoms>(atoms),\n [atoms]\n );\n\n return (\n <StoreContext.Provider value={store}>{children}</StoreContext.Provider>\n );\n };\n\n return {\n ContextQueryProvider,\n StoreContext,\n };\n}\n","import type { ContextQueryStore } from \"@context-query/core\";\nimport { createContext } from \"react\";\n\nexport const createStoreContext = <TAtoms extends Record<string, any>>() => {\n return createContext<ContextQueryStore<TAtoms> | null>(null);\n};\n","import { \n createUseContextAtom, \n createUseContextAtomValue, \n createUseContextSetAtom,\n createUseStore,\n createUseAllAtoms,\n createUseAllAtomsValue,\n createUseUpdateAllAtoms\n} from \"./hooks\";\nimport { createReactContextQuery } from \"./provider\";\n\nexport function createContextQuery<TAtoms extends Record<string, any>>() {\n const { ContextQueryProvider, StoreContext } =\n createReactContextQuery<TAtoms>();\n \n const useContextAtom = createUseContextAtom<TAtoms>(StoreContext);\n const useContextAtomValue = createUseContextAtomValue<TAtoms>(StoreContext);\n const useContextSetAtom = createUseContextSetAtom<TAtoms>(StoreContext);\n const useStore = createUseStore<TAtoms>(StoreContext);\n const useAllAtoms = createUseAllAtoms<TAtoms>(StoreContext);\n const useAllAtomsValue = createUseAllAtomsValue<TAtoms>(StoreContext);\n const useUpdateAllAtoms = createUseUpdateAllAtoms<TAtoms>(StoreContext);\n \n return {\n ContextQueryProvider,\n useContextAtom,\n useContextAtomValue,\n useContextSetAtom,\n useStore,\n useAllAtoms,\n useAllAtomsValue,\n useUpdateAllAtoms,\n };\n}\n"],"names":["createUseContextAtom","StoreContext","key","store","useContext","Error","useStore","value","setValue","useState","getAtomValue","useEffect","subscription","subscribeToAtom","_","newValue","unsubscribe","useCallback","currentValue","updatedValue","setAtomValue","createUseContextAtomValue","createUseContextSetAtom","createUseAllAtoms","allValues","setAllValues","getAllAtomValues","subscriptions","currentAtoms","Object","keys","forEach","push","sub","newAtoms","updateAllAtoms","createUseAllAtomsValue","createUseUpdateAllAtoms","t","listeners","constructor","this","Set","getValue","is","notifyListeners","subscribe","add","delete","e","atoms","Map","entries","s","set","get","String","createReactContextQuery","createContext","ContextQueryProvider","children","useMemo","ContextQueryStore","_jsx","Provider","createContextQuery","useContextAtom","useContextAtomValue","useContextSetAtom","createUseStore","useAllAtoms","useAllAtomsValue","useUpdateAllAtoms"],"mappings":"yJAkBM,SAAUA,EACdC,GAcA,OAAmCC,IACjC,MAAMC,EAbS,MACf,MAAMA,EAAQC,EAAWH,GAEzB,IAAKE,EACH,MAAM,IAAIE,MACR,6DAIJ,OAAOF,CAAK,EAIEG,IACPC,EAAOC,GAAYC,GAAuB,IAC/CN,EAAMO,aAAaR,KAGrBS,GAAU,KACRH,EAASL,EAAMO,aAAaR,GAAK,GAChC,CAACC,EAAOD,IAEXS,GAAU,KACR,MAIMC,EAAeT,EAAMU,gBAAgBX,GAJtB,CAACY,EAASC,KAC7BP,EAASO,EAAS,IAKpB,MAAO,KACLH,EAAaI,aAAa,CAC3B,GACA,CAACd,EAAKC,IAeT,MAAO,CAACI,EAbQU,GACbF,IACC,MAAMG,EAAef,EAAMO,aAAaR,GAClCiB,EACgB,mBAAbJ,EACFA,EAAsBG,GACvBH,EAENZ,EAAMiB,aAAalB,EAAKiB,EAAa,GAEvC,CAACjB,EAAKC,IAGwB,CAEpC,CAEM,SAAUkB,EACdpB,GAcA,OAAmCC,IACjC,MAAMC,EAbS,MACf,MAAMA,EAAQC,EAAWH,GAEzB,IAAKE,EACH,MAAM,IAAIE,MACR,kEAIJ,OAAOF,CAAK,EAIEG,IACPC,EAAOC,GAAYC,GAAuB,IAC/CN,EAAMO,aAAaR,KAmBrB,OAhBAS,GAAU,KACRH,EAASL,EAAMO,aAAaR,GAAK,GAChC,CAACC,EAAOD,IAEXS,GAAU,KACR,MAIMC,EAAeT,EAAMU,gBAAgBX,GAJtB,CAACY,EAASC,KAC7BP,EAASO,EAAS,IAKpB,MAAO,KACLH,EAAaI,aAAa,CAC3B,GACA,CAACd,EAAKC,IAEFI,CAAK,CAEh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MAAO,CACL0D,uBACAO,iBACAC,sBACAC,oBACA9D,WACAgE,YAVkB/C,EAA0BtB,GAW5CsE,iBAVuBnC,EAA+BnC,GAWtDuE,kBAVwBnC,EAAgCpC,GAY5D","x_google_ignoreList":[1]}
1
+ {"version":3,"file":"index.mjs","sources":["../src/use-store-context.ts","../src/use-atom-subscription.ts","../../core/dist/index.mjs","../src/provider.tsx","../src/context.ts","../src/index.ts","../src/hooks/use-context-atom.ts","../src/hooks/use-context-atom-value.ts","../src/hooks/use-context-set-atom.ts","../src/hooks/use-store.ts","../src/hooks/use-all-atoms.ts","../src/hooks/use-all-atoms-value.ts","../src/hooks/use-update-all-atoms.ts"],"sourcesContent":["import type { ContextQueryStore } from \"@context-query/core\";\nimport { useContext } from \"react\";\nimport { createStoreContext } from \"./context\";\n\nexport function createUseStoreContext<TAtoms extends Record<string, any>>(\n StoreContext: ReturnType<typeof createStoreContext<TAtoms>>\n): () => ContextQueryStore<TAtoms> {\n return (): ContextQueryStore<TAtoms> => {\n const store = useContext(StoreContext);\n\n if (!store) {\n throw new Error(\"Hook must be used within a ContextQueryProvider\");\n }\n\n return store;\n };\n}\n","import type { ContextQueryStore } from \"@context-query/core\";\nimport { useCallback, useSyncExternalStore } from \"react\";\n\nexport function useAtomSubscription<\n TAtoms extends Record<string, any>,\n TKey extends keyof TAtoms,\n>(store: ContextQueryStore<TAtoms>, key: TKey): TAtoms[TKey] {\n const subscribe = useCallback(\n (callback: () => void) => {\n const subscription = store.subscribeToAtom(key, () => {\n callback();\n });\n return () => subscription.unsubscribe();\n },\n [store, key]\n );\n\n const getSnapshot = useCallback(\n () => store.getAtomValue(key),\n [store, key]\n );\n\n return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n}\n","class t{value;listeners;constructor(t){this.value=t,this.listeners=new Set}getValue(){return this.value}setValue(t){Object.is(this.value,t)||(this.value=t,this.notifyListeners())}notifyListeners(){this.listeners.forEach(t=>t())}subscribe(t){this.listeners.add(t);return{unsubscribe:()=>{this.listeners.delete(t)}}}}class s{atoms;cachedAllValues=null;allValuesDirty=!0;constructor(s){this.atoms=new Map,Object.entries(s).forEach(([s,e])=>{const l=new t(e);this.atoms.set(s,l),l.subscribe(()=>{this.allValuesDirty=!0})})}getAtom(t){const s=this.atoms.get(t);if(!s)throw new Error(`Atom with key \"${String(t)}\" not found`);return s}getAtomValue(t){return this.getAtom(t).getValue()}setAtomValue(t,s){this.getAtom(t).setValue(s)}subscribeToAtom(t,s){return this.getAtom(t).subscribe(e=>{s(t,e)})}getAllAtomValues(){if(!this.allValuesDirty&&null!==this.cachedAllValues)return this.cachedAllValues;const t={};return this.atoms.forEach((s,e)=>{t[e]=s.getValue()}),this.cachedAllValues=t,this.allValuesDirty=!1,t}updateAllAtoms(t){Object.entries(t).forEach(([t,s])=>{const e=this.atoms.get(t);e&&e.setValue(s)})}subscribeAll(t){const s=[];return this.atoms.forEach(e=>{const l=e.subscribe(()=>{t(this.getAllAtomValues())});s.push(l)}),{unsubscribe:()=>{s.forEach(t=>t.unsubscribe())}}}}export{t as AtomStore,s as ContextQueryStore};\n//# sourceMappingURL=index.mjs.map\n","import { ContextQueryStore } from \"@context-query/core\";\nimport { PropsWithChildren, useMemo } from \"react\";\nimport { createStoreContext } from \"./context\";\n\ntype AtomValues<T extends Record<string, any>> = {\n [K in keyof T]: T[K];\n};\n\nexport function createReactContextQuery<TAtoms extends Record<string, any>>() {\n const StoreContext = createStoreContext<TAtoms>();\n \n const ContextQueryProvider = function ContextQueryProvider({\n children,\n atoms,\n }: PropsWithChildren<{ atoms: AtomValues<TAtoms> }>) {\n const store = useMemo(\n () => new ContextQueryStore<TAtoms>(atoms),\n [atoms]\n );\n\n return (\n <StoreContext.Provider value={store}>{children}</StoreContext.Provider>\n );\n };\n\n return {\n ContextQueryProvider,\n StoreContext,\n };\n}\n","import type { ContextQueryStore } from \"@context-query/core\";\nimport { createContext } from \"react\";\n\nexport const createStoreContext = <TAtoms extends Record<string, any>>() => {\n return createContext<ContextQueryStore<TAtoms> | null>(null);\n};\n","import {\n createUseContextAtom,\n createUseContextAtomValue,\n createUseContextSetAtom,\n createUseStore,\n createUseAllAtoms,\n createUseAllAtomsValue,\n createUseUpdateAllAtoms\n} from \"./hooks\";\nimport { createReactContextQuery } from \"./provider\";\n\nexport function createContextQuery<TAtoms extends Record<string, any>>() {\n const { ContextQueryProvider, StoreContext } =\n createReactContextQuery<TAtoms>();\n\n const useContextAtom = createUseContextAtom<TAtoms>(StoreContext);\n const useContextAtomValue = createUseContextAtomValue<TAtoms>(StoreContext);\n const useContextSetAtom = createUseContextSetAtom<TAtoms>(StoreContext);\n const useStore = createUseStore<TAtoms>(StoreContext);\n const useAllAtoms = createUseAllAtoms<TAtoms>(StoreContext);\n const useAllAtomsValue = createUseAllAtomsValue<TAtoms>(StoreContext);\n const useUpdateAllAtoms = createUseUpdateAllAtoms<TAtoms>(StoreContext);\n\n return {\n ContextQueryProvider,\n useContextAtom,\n useContextAtomValue,\n useContextSetAtom,\n useStore,\n useAllAtoms,\n useAllAtomsValue,\n useUpdateAllAtoms,\n };\n}\n","import type { ContextQueryStore } from \"@context-query/core\";\nimport { useCallback } from \"react\";\nimport { createStoreContext } from \"../context\";\nimport { createUseStoreContext } from \"../use-store-context\";\nimport { useAtomSubscription } from \"../use-atom-subscription\";\n\nexport function createUseContextAtom<TAtoms extends Record<string, any>>(\n StoreContext: ReturnType<typeof createStoreContext<TAtoms>>\n) {\n const useStoreContext = createUseStoreContext<TAtoms>(StoreContext);\n\n return <TKey extends keyof TAtoms>(key: TKey) => {\n const store = useStoreContext();\n const value = useAtomSubscription(store, key);\n\n const setAtom = useCallback(\n (newValue: TAtoms[TKey] | ((prev: TAtoms[TKey]) => TAtoms[TKey])) => {\n const currentValue = store.getAtomValue(key);\n const updatedValue =\n typeof newValue === \"function\"\n ? (newValue as Function)(currentValue)\n : newValue;\n\n store.setAtomValue(key, updatedValue);\n },\n [key, store]\n );\n\n return [value, setAtom] as const;\n };\n}\n","import { createStoreContext } from \"../context\";\nimport { createUseStoreContext } from \"../use-store-context\";\nimport { useAtomSubscription } from \"../use-atom-subscription\";\n\nexport function createUseContextAtomValue<TAtoms extends Record<string, any>>(\n StoreContext: ReturnType<typeof createStoreContext<TAtoms>>\n) {\n const useStoreContext = createUseStoreContext<TAtoms>(StoreContext);\n\n return <TKey extends keyof TAtoms>(key: TKey): TAtoms[TKey] => {\n const store = useStoreContext();\n return useAtomSubscription(store, key);\n };\n}\n","import { useCallback } from \"react\";\nimport { createStoreContext } from \"../context\";\nimport { createUseStoreContext } from \"../use-store-context\";\n\nexport function createUseContextSetAtom<TAtoms extends Record<string, any>>(\n StoreContext: ReturnType<typeof createStoreContext<TAtoms>>\n) {\n const useStoreContext = createUseStoreContext<TAtoms>(StoreContext);\n\n return <TKey extends keyof TAtoms>(\n key: TKey\n ): ((\n value: TAtoms[TKey] | ((prev: TAtoms[TKey]) => TAtoms[TKey])\n ) => void) => {\n const store = useStoreContext();\n\n return useCallback(\n (newValue: TAtoms[TKey] | ((prev: TAtoms[TKey]) => TAtoms[TKey])) => {\n const currentValue = store.getAtomValue(key);\n const updatedValue =\n typeof newValue === \"function\"\n ? (newValue as Function)(currentValue)\n : newValue;\n\n store.setAtomValue(key, updatedValue);\n },\n [key, store]\n );\n };\n}\n","import type { ContextQueryStore } from \"@context-query/core\";\nimport { createStoreContext } from \"../context\";\nimport { createUseStoreContext } from \"../use-store-context\";\n\nexport function createUseStore<TAtoms extends Record<string, any>>(\n StoreContext: ReturnType<typeof createStoreContext<TAtoms>>\n): () => ContextQueryStore<TAtoms> {\n const useStoreContext = createUseStoreContext<TAtoms>(StoreContext);\n\n return () => {\n return useStoreContext();\n };\n}\n","import { useCallback, useSyncExternalStore } from \"react\";\nimport { createStoreContext } from \"../context\";\nimport { createUseStoreContext } from \"../use-store-context\";\n\nexport function createUseAllAtoms<TAtoms extends Record<string, any>>(\n StoreContext: ReturnType<typeof createStoreContext<TAtoms>>\n) {\n const useStoreContext = createUseStoreContext<TAtoms>(StoreContext);\n\n return (): [TAtoms, (newAtoms: Partial<TAtoms>) => void] => {\n const store = useStoreContext();\n\n const subscribe = useCallback(\n (callback: () => void) => {\n const subscription = store.subscribeAll(() => {\n callback();\n });\n return () => subscription.unsubscribe();\n },\n [store]\n );\n\n const getSnapshot = useCallback(\n () => store.getAllAtomValues(),\n [store]\n );\n\n const allValues = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n\n const updateAllAtoms = useCallback(\n (newAtoms: Partial<TAtoms>) => {\n store.updateAllAtoms(newAtoms);\n },\n [store]\n );\n\n return [allValues, updateAllAtoms] as const;\n };\n}\n","import { useCallback, useSyncExternalStore } from \"react\";\nimport { createStoreContext } from \"../context\";\nimport { createUseStoreContext } from \"../use-store-context\";\n\nexport function createUseAllAtomsValue<TAtoms extends Record<string, any>>(\n StoreContext: ReturnType<typeof createStoreContext<TAtoms>>\n) {\n const useStoreContext = createUseStoreContext<TAtoms>(StoreContext);\n\n return (): TAtoms => {\n const store = useStoreContext();\n\n const subscribe = useCallback(\n (callback: () => void) => {\n const subscription = store.subscribeAll(() => {\n callback();\n });\n return () => subscription.unsubscribe();\n },\n [store]\n );\n\n const getSnapshot = useCallback(\n () => store.getAllAtomValues(),\n [store]\n );\n\n return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n };\n}\n","import { useCallback } from \"react\";\nimport { createStoreContext } from \"../context\";\nimport { createUseStoreContext } from \"../use-store-context\";\n\nexport function createUseUpdateAllAtoms<TAtoms extends Record<string, any>>(\n StoreContext: ReturnType<typeof createStoreContext<TAtoms>>\n) {\n const useStoreContext = createUseStoreContext<TAtoms>(StoreContext);\n\n return (): ((newAtoms: Partial<TAtoms>) => void) => {\n const store = useStoreContext();\n\n return useCallback(\n (newAtoms: Partial<TAtoms>) => {\n store.updateAllAtoms(newAtoms);\n },\n [store]\n );\n };\n}\n"],"names":["createUseStoreContext","StoreContext","store","useContext","Error","useAtomSubscription","key","subscribe","useCallback","callback","subscription","subscribeToAtom","unsubscribe","getSnapshot","getAtomValue","useSyncExternalStore","t","value","listeners","constructor","this","Set","getValue","setValue","Object","is","notifyListeners","forEach","add","delete","s","atoms","cachedAllValues","allValuesDirty","Map","entries","e","l","set","getAtom","get","String","setAtomValue","getAllAtomValues","updateAllAtoms","subscribeAll","push","createReactContextQuery","createContext","ContextQueryProvider","children","useMemo","ContextQueryStore","_jsx","Provider","createContextQuery","useContextAtom","useStoreContext","newValue","currentValue","updatedValue","createUseContextAtom","useContextAtomValue","createUseContextAtomValue","useContextSetAtom","createUseContextSetAtom","useStore","createUseStore","useAllAtoms","newAtoms","createUseAllAtoms","useAllAtomsValue","createUseAllAtomsValue","useUpdateAllAtoms","createUseUpdateAllAtoms"],"mappings":"sJAIM,SAAUA,EACdC,GAEA,MAAO,KACL,MAAMC,EAAQC,EAAWF,GAEzB,IAAKC,EACH,MAAM,IAAIE,MAAM,mDAGlB,OAAOF,EAEX,CCbM,SAAUG,EAGdH,EAAkCI,GAClC,MAAMC,EAAYC,EACfC,IACC,MAAMC,EAAeR,EAAMS,gBAAgBL,EAAK,KAC9CG,MAEF,MAAO,IAAMC,EAAaE,eAE5B,CAACV,EAAOI,IAGJO,EAAcL,EAClB,IAAMN,EAAMY,aAAaR,GACzB,CAACJ,EAAOI,IAGV,OAAOS,EAAqBR,EAAWM,EAAaA,EACtD,CCvBA,MAAMG,EAAEC,MAAMC,UAAU,WAAAC,CAAYH,GAAGI,KAAKH,MAAMD,EAAEI,KAAKF,UAAU,IAAIG,GAAG,CAAC,QAAAC,GAAW,OAAOF,KAAKH,KAAK,CAAC,QAAAM,CAASP,GAAGQ,OAAOC,GAAGL,KAAKH,MAAMD,KAAKI,KAAKH,MAAMD,EAAEI,KAAKM,kBAAkB,CAAC,eAAAA,GAAkBN,KAAKF,UAAUS,QAAQX,GAAGA,IAAI,CAAC,SAAAT,CAAUS,GAAyB,OAAtBI,KAAKF,UAAUU,IAAIZ,GAAS,CAACJ,YAAY,KAAKQ,KAAKF,UAAUW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8BC,GAEtD,MAAO,KACL,MAAMC,EAAQuD,IAERlD,EAAYC,EACfC,IACC,MAAMC,EAAeR,EAAM2C,aAAa,KACtCpC,MAEF,MAAO,IAAMC,EAAaE,eAE5B,CAACV,IAGGW,EAAcL,EAClB,IAAMN,EAAMyC,mBACZ,CAACzC,IAYH,MAAO,CATWa,EAAqBR,EAAWM,EAAaA,GAExCL,EACpB6D,IACCnE,EAAM0C,eAAeyB,IAEvB,CAACnE,KAKP,CLnBsBoE,CAA0BrE,GACxCsE,EMhBF,SACJtE,GAEA,MAAMwD,EAAkBzD,EAA8BC,GAEtD,MAAO,KACL,MAAMC,EAAQuD,IAERlD,EAAYC,EACfC,IACC,MAAMC,EAAeR,EAAM2C,aAAa,KACtCpC,MAEF,MAAO,IAAMC,EAAaE,eAE5B,CAACV,IAGGW,EAAcL,EAClB,IAAMN,EAAMyC,mBACZ,CAACzC,IAGH,OAAOa,EAAqBR,EAAWM,EAAaA,GAExD,CNT2B2D,CAA+BvE,GAClDwE,EOjBF,SACJxE,GAEA,MAAMwD,EAAkBzD,EAA8BC,GAEtD,MAAO,KACL,MAAMC,EAAQuD,IAEd,OAAOjD,EACJ6D,IACCnE,EAAM0C,eAAeyB,IAEvB,CAACnE,IAGP,CPE4BwE,CAAgCzE,GAE1D,MAAO,CACLgD,uBACAO,iBACAM,sBACAE,oBACAE,WACAE,cACAG,mBACAE,oBAEJ"}
@@ -0,0 +1,2 @@
1
+ import type { ContextQueryStore } from "@context-query/core";
2
+ export declare function useAtomSubscription<TAtoms extends Record<string, any>, TKey extends keyof TAtoms>(store: ContextQueryStore<TAtoms>, key: TKey): TAtoms[TKey];
@@ -0,0 +1,3 @@
1
+ import type { ContextQueryStore } from "@context-query/core";
2
+ import { createStoreContext } from "./context";
3
+ export declare function createUseStoreContext<TAtoms extends Record<string, any>>(StoreContext: ReturnType<typeof createStoreContext<TAtoms>>): () => ContextQueryStore<TAtoms>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@context-query/react",
3
- "version": "0.3.2-beta.4",
3
+ "version": "0.4.0",
4
4
  "license": "MIT",
5
5
  "description": "React bindings for ContextQuery",
6
6
  "author": "Minyeoung Seo <tjalsdud89@naver.com>",
@@ -16,10 +16,6 @@
16
16
  "state",
17
17
  "management"
18
18
  ],
19
- "scripts": {
20
- "build": "rollup -c",
21
- "dev": "rollup -c -w"
22
- },
23
19
  "main": "./dist/index.cjs",
24
20
  "module": "./dist/index.mjs",
25
21
  "types": "./dist/index.d.ts",
@@ -38,11 +34,14 @@
38
34
  "react": "^18.0.0 || ^19.0.0"
39
35
  },
40
36
  "dependencies": {
41
- "@context-query/core": "0.3.2-beta.1",
42
- "react": "^18.3.1"
37
+ "react": "^18.3.1",
38
+ "@context-query/core": "0.5.0"
43
39
  },
44
40
  "devDependencies": {
45
41
  "@types/react": "^19.0.10"
46
42
  },
47
- "packageManager": "pnpm@9.0.0"
48
- }
43
+ "scripts": {
44
+ "build": "rollup -c",
45
+ "dev": "rollup -c -w"
46
+ }
47
+ }
package/dist/hooks.d.ts DELETED
@@ -1,9 +0,0 @@
1
- import type { ContextQueryStore } from "@context-query/core";
2
- import { createStoreContext } from "./context";
3
- export declare function createUseStore<TAtoms extends Record<string, any>>(StoreContext: ReturnType<typeof createStoreContext<TAtoms>>): () => ContextQueryStore<TAtoms>;
4
- export declare function createUseContextAtom<TAtoms extends Record<string, any>>(StoreContext: ReturnType<typeof createStoreContext<TAtoms>>): <TKey extends keyof TAtoms>(key: TKey) => readonly [TAtoms[TKey], (newValue: TAtoms[TKey] | ((prev: TAtoms[TKey]) => TAtoms[TKey])) => void];
5
- export declare function createUseContextAtomValue<TAtoms extends Record<string, any>>(StoreContext: ReturnType<typeof createStoreContext<TAtoms>>): <TKey extends keyof TAtoms>(key: TKey) => TAtoms[TKey];
6
- export declare function createUseContextSetAtom<TAtoms extends Record<string, any>>(StoreContext: ReturnType<typeof createStoreContext<TAtoms>>): <TKey extends keyof TAtoms>(key: TKey) => ((value: TAtoms[TKey] | ((prev: TAtoms[TKey]) => TAtoms[TKey])) => void);
7
- export declare function createUseAllAtoms<TAtoms extends Record<string, any>>(StoreContext: ReturnType<typeof createStoreContext<TAtoms>>): () => [TAtoms, (newAtoms: Partial<TAtoms>) => void];
8
- export declare function createUseAllAtomsValue<TAtoms extends Record<string, any>>(StoreContext: ReturnType<typeof createStoreContext<TAtoms>>): () => TAtoms;
9
- export declare function createUseUpdateAllAtoms<TAtoms extends Record<string, any>>(StoreContext: ReturnType<typeof createStoreContext<TAtoms>>): () => ((newAtoms: Partial<TAtoms>) => void);