@context-query/react 0.3.1 → 0.3.2-beta.3
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/context.d.ts +2 -2
- package/dist/hooks.d.ts +8 -3
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +11 -5
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/provider.d.ts +10 -4
- package/package.json +2 -2
package/dist/context.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { ContextQueryStore
|
|
2
|
-
export declare const createStoreContext: <
|
|
1
|
+
import type { ContextQueryStore } from "@context-query/core";
|
|
2
|
+
export declare const createStoreContext: <TAtoms extends Record<string, any>>() => import("react").Context<ContextQueryStore<TAtoms> | null>;
|
package/dist/hooks.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import { TStateImpl } from "@context-query/core";
|
|
2
1
|
import { createStoreContext } from "./context";
|
|
3
|
-
|
|
4
|
-
export declare function
|
|
2
|
+
import type { ContextQueryStore } from "@context-query/core";
|
|
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);
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var t=require("react"),e=require("react/jsx-runtime");function
|
|
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((()=>{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((()=>{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((()=>{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((()=>{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 c{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 l{atoms;constructor(t){this.atoms=new Map,Object.entries(t).forEach((([t,e])=>{this.atoms.set(t,new c(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 l(o)),[o]);return e.jsx(r.Provider,{value:u,children:s})},StoreContext:r}}exports.createContextQuery=function(){const{ContextQueryProvider:e,StoreContext:c}=a(),l=r(c),m=s(c),A=o(c),h=function(e){return()=>{const r=t.useContext(e);if(!r)throw new Error("useStore must be used within a ContextQueryProvider");return r}}(c);return{ContextQueryProvider:e,useContextAtom:l,useContextAtomValue:m,useContextSetAtom:A,useStore:h,useAllAtoms:u(c),useAllAtomsValue:n(c),useUpdateAllAtoms:i(c)}};
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/hooks.ts","../../../node_modules/.pnpm/@context-query+core@0.3.0-beta.1/node_modules/@context-query/core/dist/index.mjs","../src/provider.tsx","../src/context.ts","../src/index.ts"],"sourcesContent":["import { TStateImpl } from \"@context-query/core\";\nimport { useCallback, useContext, useEffect, useState } from \"react\";\nimport { createStoreContext } from \"./context\";\n\nexport function createUseContextQuery<TState extends TStateImpl>(\n contexts: ReturnType<typeof createStoreContext<TState>>\n) {\n const useStore = () => {\n const store = useContext(contexts);\n\n if (!store) {\n throw new Error(\n \"useContextQuery must be used within a ContextQueryProvider\"\n );\n }\n\n return store;\n };\n\n return <TKey extends keyof TState>(keys?: TKey[]) => {\n const store = useStore();\n const localKeys = keys ?? (Object.keys(store.getState()) as TKey[]);\n\n type StateSubset = { [K in TKey]: TState[K] };\n\n const getStateSubset = (): StateSubset => {\n return localKeys.reduce(\n (acc, key) => ({ ...acc, [key]: store.getStateByKey(key) }),\n {} as StateSubset\n );\n };\n\n const [state, setLocalState] = useState<StateSubset>(getStateSubset);\n\n useEffect(() => {\n const handleChange = (key: TKey, newValue: TState[TKey]) => {\n setLocalState((prev) => ({ ...prev, [key]: newValue }));\n };\n\n const subscriptions = localKeys.map((key) =>\n store.subscribe(key, handleChange)\n );\n\n return () => {\n subscriptions.forEach((sub) => sub.unsubscribe());\n };\n }, [localKeys, store]);\n\n const setState = useCallback(\n (value: StateSubset | ((prev: StateSubset) => StateSubset)) => {\n const currentValue = getStateSubset();\n const updatedValue =\n typeof value === \"function\"\n ? (value as Function)(currentValue)\n : value;\n\n Object.entries(updatedValue).forEach(([k, v]) => {\n store.setState(k as TKey, v as TState[TKey]);\n });\n },\n [localKeys, store]\n );\n\n return [state, setState] as const;\n };\n}\n\nexport function createUseContextSetter<TState extends TStateImpl>(\n StoreContext: ReturnType<typeof createStoreContext<TState>>\n) {\n return () => {\n const store = useContext(StoreContext);\n \n if (!store) {\n throw new Error(\"useContextSetter must be used within a ContextQueryProvider\");\n }\n \n const setState = useCallback((updater: Partial<TState> | ((prev: TState) => Partial<TState>)) => {\n const currentState = store.getState();\n const newState = typeof updater === 'function' ? updater(currentState) : updater;\n \n Object.entries(newState).forEach(([key, value]) => {\n store.setState(key as keyof TState, value as TState[keyof TState]);\n });\n }, [store]);\n \n return setState;\n };\n}\n","class t{state;listeners;constructor(t){this.state=t,this.listeners=new Map}getState(){return this.state}getStateByKey(t){return this.state[t]}updateState(t){const s={...this.state};this.state={...t};Object.keys(t).forEach((t=>{Object.is(s[t],this.state[t])||this.notifyListeners(t)}))}setState(t,s){Object.is(this.state[t],s)||(this.state={...this.state,[t]:s},this.notifyListeners(t))}notifyListeners(t){const s=this.listeners.get(t);if(s){const e=this.state[t];s.forEach((t=>t(e)))}}subscribe(t,s){const e=e=>{s(t,e)};this.listeners.has(t)||this.listeners.set(t,new Set),this.listeners.get(t).add(e);return{unsubscribe:()=>{const s=this.listeners.get(t);s&&(s.delete(e),0===s.size&&this.listeners.delete(t))}}}}export{t as ContextQueryStore};\n//# sourceMappingURL=index.mjs.map\n","import { ContextQueryStore, TStateImpl } from \"@context-query/core\";\nimport { PropsWithChildren, useMemo } from \"react\";\nimport { createStoreContext } from \"./context\";\n\nexport function createReactContextQuery<TState extends TStateImpl>() {\n const StoreContext = createStoreContext<TState>();\n const ContextQueryProvider = function ContextQueryProvider({\n children,\n initialState,\n }: PropsWithChildren<TState>) {\n const store = useMemo(\n () => new ContextQueryStore<TState>(initialState),\n [initialState]\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, TStateImpl } from \"@context-query/core\";\nimport { createContext } from \"react\";\n\nexport const createStoreContext = <TState extends TStateImpl>() => {\n return createContext<ContextQueryStore<TState> | null>(null);\n};\n","import { TStateImpl } from \"@context-query/core\";\nimport { createUseContextQuery, createUseContextSetter } from \"./hooks\";\nimport { createReactContextQuery } from \"./provider\";\n\nexport function createContextQuery<TState extends TStateImpl>() {\n const { ContextQueryProvider, StoreContext } =\n createReactContextQuery<TState>();\n const useContextQuery = createUseContextQuery<TState>(StoreContext);\n const useContextSetter = createUseContextSetter<TState>(StoreContext);\n return {\n ContextQueryProvider,\n useContextQuery,\n useContextSetter,\n };\n}\n"],"names":["createUseContextQuery","contexts","keys","store","useContext","Error","useStore","localKeys","Object","getState","getStateSubset","reduce","acc","key","getStateByKey","state","setLocalState","useState","useEffect","handleChange","newValue","prev","subscriptions","map","subscribe","forEach","sub","unsubscribe","useCallback","value","currentValue","updatedValue","entries","k","v","setState","t","listeners","constructor","this","Map","updateState","s","is","notifyListeners","get","e","has","set","Set","add","delete","size","createReactContextQuery","StoreContext","createContext","ContextQueryProvider","children","initialState","useMemo","ContextQueryStore","_jsx","jsx","Provider","useContextQuery","useContextSetter","updater","currentState","newState","createUseContextSetter"],"mappings":"mEAIM,SAAUA,EACdC,GAcA,OAAmCC,IACjC,MAAMC,EAbS,MACf,MAAMA,EAAQC,EAAUA,WAACH,GAEzB,IAAKE,EACH,MAAM,IAAIE,MACR,8DAIJ,OAAOF,CAAK,EAIEG,GACRC,EAAYL,GAASM,OAAON,KAAKC,EAAMM,YAIvCC,EAAiB,IACdH,EAAUI,Q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}
|
|
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 { useCallback, useContext, useEffect, useState } from \"react\";\nimport { createStoreContext } from \"./context\";\nimport type { ContextQueryStore } from \"@context-query/core\";\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(\n \"useStore must be used within a ContextQueryProvider\"\n );\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 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 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(\n \"useAllAtoms must be used within a ContextQueryProvider\"\n );\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 // Subscribe to all atoms by getting all keys and subscribing to each\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 // Subscribe to all atoms by getting all keys and subscribing to each\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":"mEAoBM,SAAUA,EACdC,GAcA,OAAmCC,IACjC,MAAMC,EAbS,MACf,MAAMA,EAAQC,EAAUA,WAACH,GAEzB,IAAKE,EACH,MAAM,IAAIE,MACR,6DAIJ,OAAOF,CAAK,EAIEG,IACPC,EAAOC,GA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N,UAAW,IAAGL,CAAC,CAAC,cAAAH,CAAeG,GAAGT,OAAOuB,QAAQd,GAAGP,SAAS,EAAEO,EAAEW,MAAM,MAAMI,EAAEZ,KAAKS,MAAMK,IAAIjB,GAAGe,GAAGA,EAAE7C,SAASyC,EAAG,GAAE,WCQ/+BQ,IACd,MAAMxD,ECLCyD,EAAAA,cAAgD,MDqBvD,MAAO,CACLC,qBAf2B,UAA8BC,SACzDA,EAAQV,MACRA,IAEA,MAAM/C,EAAQ0D,EAAAA,SACZ,IAAM,IAAIC,EAA0BZ,IACpC,CAACA,IAGH,OACEa,EAAAC,IAAC/D,EAAagE,SAAQ,CAAC1D,MAAOJ,EAAKyD,SAAGA,GAEzC,EAIC3D,eAEJ,uCEjBE,MAAM0D,qBAAEA,EAAoB1D,aAAEA,GAC5BwD,IAEIS,EAAiBlE,EAA6BC,GAC9CkE,EAAsB9C,EAAkCpB,GACxDmE,EAAoB9C,EAAgCrB,GACpDK,EJdF,SACJL,GAEA,MAAO,KACL,MAAME,EAAQC,EAAUA,WAACH,GAEzB,IAAKE,EACH,MAAM,IAAIE,MACR,uDAIJ,OAAOF,CAAK,CAEhB,CIAmBkE,CAAuBpE,GAKxC,MAAO,CACL0D,uBACAO,iBACAC,sBACAC,oBACA9D,WACAgE,YAVkB/C,EAA0BtB,GAW5CsE,iBAVuBnC,EAA+BnC,GAWtDuE,kBAVwBnC,EAAgCpC,GAY5D","x_google_ignoreList":[1]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
export declare function createContextQuery<TAtoms extends Record<string, any>>(): {
|
|
2
|
+
ContextQueryProvider: ({ children, atoms, }: import("react").PropsWithChildren<{
|
|
3
|
+
atoms: { [K in keyof TAtoms]: TAtoms[K]; };
|
|
4
|
+
}>) => import("react/jsx-runtime").JSX.Element;
|
|
5
|
+
useContextAtom: <TKey extends keyof TAtoms>(key: TKey) => readonly [TAtoms[TKey], (newValue: TAtoms[TKey] | ((prev: TAtoms[TKey]) => TAtoms[TKey])) => void];
|
|
6
|
+
useContextAtomValue: <TKey extends keyof TAtoms>(key: TKey) => TAtoms[TKey];
|
|
7
|
+
useContextSetAtom: <TKey extends keyof TAtoms>(key: TKey) => (value: TAtoms[TKey] | ((prev: TAtoms[TKey]) => TAtoms[TKey])) => void;
|
|
8
|
+
useStore: () => import("@context-query/core").ContextQueryStore<TAtoms>;
|
|
9
|
+
useAllAtoms: () => [TAtoms, (newAtoms: Partial<TAtoms>) => void];
|
|
10
|
+
useAllAtomsValue: () => TAtoms;
|
|
11
|
+
useUpdateAllAtoms: () => (newAtoms: Partial<TAtoms>) => void;
|
|
6
12
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
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,c]=e((()=>u.getAtomValue(n)));r((()=>{const t=u.subscribeToAtom(n,((t,e)=>{c(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 c(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((()=>{const t=n.subscribeToAtom(s,((t,e)=>{i(e)}));return()=>{t.unsubscribe()}}),[s,n]),u}}function l(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((()=>{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((()=>{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=c(e),n=l(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};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/hooks.ts","../../../node_modules/.pnpm/@context-query+core@0.3.0-beta.1/node_modules/@context-query/core/dist/index.mjs","../src/provider.tsx","../src/context.ts","../src/index.ts"],"sourcesContent":["import { TStateImpl } from \"@context-query/core\";\nimport { useCallback, useContext, useEffect, useState } from \"react\";\nimport { createStoreContext } from \"./context\";\n\nexport function createUseContextQuery<TState extends TStateImpl>(\n contexts: ReturnType<typeof createStoreContext<TState>>\n) {\n const useStore = () => {\n const store = useContext(contexts);\n\n if (!store) {\n throw new Error(\n \"useContextQuery must be used within a ContextQueryProvider\"\n );\n }\n\n return store;\n };\n\n return <TKey extends keyof TState>(keys?: TKey[]) => {\n const store = useStore();\n const localKeys = keys ?? (Object.keys(store.getState()) as TKey[]);\n\n type StateSubset = { [K in TKey]: TState[K] };\n\n const getStateSubset = (): StateSubset => {\n return localKeys.reduce(\n (acc, key) => ({ ...acc, [key]: store.getStateByKey(key) }),\n {} as StateSubset\n );\n };\n\n const [state, setLocalState] = useState<StateSubset>(getStateSubset);\n\n useEffect(() => {\n const handleChange = (key: TKey, newValue: TState[TKey]) => {\n setLocalState((prev) => ({ ...prev, [key]: newValue }));\n };\n\n const subscriptions = localKeys.map((key) =>\n store.subscribe(key, handleChange)\n );\n\n return () => {\n subscriptions.forEach((sub) => sub.unsubscribe());\n };\n }, [localKeys, store]);\n\n const setState = useCallback(\n (value: StateSubset | ((prev: StateSubset) => StateSubset)) => {\n const currentValue = getStateSubset();\n const updatedValue =\n typeof value === \"function\"\n ? (value as Function)(currentValue)\n : value;\n\n Object.entries(updatedValue).forEach(([k, v]) => {\n store.setState(k as TKey, v as TState[TKey]);\n });\n },\n [localKeys, store]\n );\n\n return [state, setState] as const;\n };\n}\n\nexport function createUseContextSetter<TState extends TStateImpl>(\n StoreContext: ReturnType<typeof createStoreContext<TState>>\n) {\n return () => {\n const store = useContext(StoreContext);\n \n if (!store) {\n throw new Error(\"useContextSetter must be used within a ContextQueryProvider\");\n }\n \n const setState = useCallback((updater: Partial<TState> | ((prev: TState) => Partial<TState>)) => {\n const currentState = store.getState();\n const newState = typeof updater === 'function' ? updater(currentState) : updater;\n \n Object.entries(newState).forEach(([key, value]) => {\n store.setState(key as keyof TState, value as TState[keyof TState]);\n });\n }, [store]);\n \n return setState;\n };\n}\n","class t{state;listeners;constructor(t){this.state=t,this.listeners=new Map}getState(){return this.state}getStateByKey(t){return this.state[t]}updateState(t){const s={...this.state};this.state={...t};Object.keys(t).forEach((t=>{Object.is(s[t],this.state[t])||this.notifyListeners(t)}))}setState(t,s){Object.is(this.state[t],s)||(this.state={...this.state,[t]:s},this.notifyListeners(t))}notifyListeners(t){const s=this.listeners.get(t);if(s){const e=this.state[t];s.forEach((t=>t(e)))}}subscribe(t,s){const e=e=>{s(t,e)};this.listeners.has(t)||this.listeners.set(t,new Set),this.listeners.get(t).add(e);return{unsubscribe:()=>{const s=this.listeners.get(t);s&&(s.delete(e),0===s.size&&this.listeners.delete(t))}}}}export{t as ContextQueryStore};\n//# sourceMappingURL=index.mjs.map\n","import { ContextQueryStore, TStateImpl } from \"@context-query/core\";\nimport { PropsWithChildren, useMemo } from \"react\";\nimport { createStoreContext } from \"./context\";\n\nexport function createReactContextQuery<TState extends TStateImpl>() {\n const StoreContext = createStoreContext<TState>();\n const ContextQueryProvider = function ContextQueryProvider({\n children,\n initialState,\n }: PropsWithChildren<TState>) {\n const store = useMemo(\n () => new ContextQueryStore<TState>(initialState),\n [initialState]\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, TStateImpl } from \"@context-query/core\";\nimport { createContext } from \"react\";\n\nexport const createStoreContext = <TState extends TStateImpl>() => {\n return createContext<ContextQueryStore<TState> | null>(null);\n};\n","import { TStateImpl } from \"@context-query/core\";\nimport { createUseContextQuery, createUseContextSetter } from \"./hooks\";\nimport { createReactContextQuery } from \"./provider\";\n\nexport function createContextQuery<TState extends TStateImpl>() {\n const { ContextQueryProvider, StoreContext } =\n createReactContextQuery<TState>();\n const useContextQuery = createUseContextQuery<TState>(StoreContext);\n const useContextSetter = createUseContextSetter<TState>(StoreContext);\n return {\n ContextQueryProvider,\n useContextQuery,\n useContextSetter,\n };\n}\n"],"names":["createUseContextQuery","contexts","keys","store","useContext","Error","useStore","localKeys","Object","getState","getStateSubset","reduce","acc","key","getStateByKey","state","setLocalState","useState","useEffect","handleChange","newValue","prev","subscriptions","map","subscribe","forEach","sub","unsubscribe","useCallback","value","currentValue","updatedValue","entries","k","v","setState","t","listeners","constructor","this","Map","updateState","s","is","notifyListeners","get","e","has","set","Set","add","delete","size","createReactContextQuery","StoreContext","createContext","ContextQueryProvider","children","initialState","useMemo","ContextQueryStore","_jsx","Provider","createContextQuery","useContextQuery","useContextSetter","updater","currentState","newState","createUseContextSetter"],"mappings":"yJAIM,SAAUA,EACdC,GAcA,OAAmCC,IACjC,MAAMC,EAbS,MACf,MAAMA,EAAQC,EAAWH,GAEzB,IAAKE,EACH,MAAM,IAAIE,MACR,8DAIJ,OAAOF,CAAK,EAIEG,GACRC,EAAYL,GAASM,OAAON,KAAKC,EAAMM,YAIvCC,EAAiB,IACdH,EAAUI,QACf,CAACC,EAAKC,KAAS,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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 { useCallback, useContext, useEffect, useState } from \"react\";\nimport { createStoreContext } from \"./context\";\nimport type { ContextQueryStore } from \"@context-query/core\";\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(\n \"useStore must be used within a ContextQueryProvider\"\n );\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 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 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(\n \"useAllAtoms must be used within a ContextQueryProvider\"\n );\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 // Subscribe to all atoms by getting all keys and subscribing to each\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 // Subscribe to all atoms by getting all keys and subscribing to each\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":"yJAoBM,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,KACR,MAIM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,SAASyC,EAAG,GAAE,WCQ/+BQ,IACd,MAAMxD,ECLCyD,EAAgD,MDqBvD,MAAO,CACLC,qBAf2B,UAA8BC,SACzDA,EAAQV,MACRA,IAEA,MAAM/C,EAAQ0D,GACZ,IAAM,IAAIC,EAA0BZ,IACpC,CAACA,IAGH,OACEa,EAAC9D,EAAa+D,SAAQ,CAACzD,MAAOJ,EAAKyD,SAAGA,GAEzC,EAIC3D,eAEJ,UElBgBgE,IACd,MAAMN,qBAAEA,EAAoB1D,aAAEA,GAC5BwD,IAEIS,EAAiBlE,EAA6BC,GAC9CkE,EAAsB9C,EAAkCpB,GACxDmE,EAAoB9C,EAAgCrB,GACpDK,EJdF,SACJL,GAEA,MAAO,KACL,MAAME,EAAQC,EAAWH,GAEzB,IAAKE,EACH,MAAM,IAAIE,MACR,uDAIJ,OAAOF,CAAK,CAEhB,CIAmBkE,CAAuBpE,GAKxC,MAAO,CACL0D,uBACAO,iBACAC,sBACAC,oBACA9D,WACAgE,YAVkB/C,EAA0BtB,GAW5CsE,iBAVuBnC,EAA+BnC,GAWtDuE,kBAVwBnC,EAAgCpC,GAY5D","x_google_ignoreList":[1]}
|
package/dist/provider.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
import { ContextQueryStore
|
|
1
|
+
import { ContextQueryStore } from "@context-query/core";
|
|
2
2
|
import { PropsWithChildren } from "react";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
StoreContext: import("react").Context<ContextQueryStore<TState> | null>;
|
|
3
|
+
type AtomValues<T extends Record<string, any>> = {
|
|
4
|
+
[K in keyof T]: T[K];
|
|
6
5
|
};
|
|
6
|
+
export declare function createReactContextQuery<TAtoms extends Record<string, any>>(): {
|
|
7
|
+
ContextQueryProvider: ({ children, atoms, }: PropsWithChildren<{
|
|
8
|
+
atoms: AtomValues<TAtoms>;
|
|
9
|
+
}>) => import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
StoreContext: import("react").Context<ContextQueryStore<TAtoms> | null>;
|
|
11
|
+
};
|
|
12
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@context-query/react",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2-beta.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "React bindings for ContextQuery",
|
|
6
6
|
"author": "Minyeoung Seo <tjalsdud89@naver.com>",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"react": "^18.0.0 || ^19.0.0"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@context-query/core": "0.3.
|
|
41
|
+
"@context-query/core": "0.3.2-beta.1",
|
|
42
42
|
"react": "^18.3.1"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|