@context-query/core 0.3.2-beta.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,5 +6,5 @@ export declare class AtomStore<T> {
6
6
  getValue(): T;
7
7
  setValue(newValue: T): void;
8
8
  private notifyListeners;
9
- subscribe(listener: AtomListener<T>): Subscription;
9
+ subscribe(listener: AtomListener): Subscription;
10
10
  }
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";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)}}}}exports.AtomStore=t,exports.ContextQueryStore=class{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)}))}};
1
+ "use strict";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)}}}}exports.AtomStore=t,exports.ContextQueryStore=class{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(e)}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)}))}};
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/atom-store.ts","../src/store.ts"],"sourcesContent":["import { AtomListener, Subscription } from \"./types\";\n\nexport class AtomStore<T> {\n private value: T;\n private listeners: Set<AtomListener<T>>;\n\n constructor(initialValue: T) {\n this.value = initialValue;\n this.listeners = new Set();\n }\n\n public getValue(): T {\n return this.value;\n }\n\n public setValue(newValue: T): void {\n if (Object.is(this.value, newValue)) {\n return;\n }\n\n this.value = newValue;\n this.notifyListeners();\n }\n\n private notifyListeners(): void {\n this.listeners.forEach((listener) => listener(this.value));\n }\n\n public subscribe(listener: AtomListener<T>): Subscription {\n this.listeners.add(listener);\n\n const unsubscribe = () => {\n this.listeners.delete(listener);\n };\n\n return {\n unsubscribe,\n };\n }\n}","import { AtomStore } from \"./atom-store\";\nimport { Subscription } from \"./types\";\n\nexport class ContextQueryStore<TAtoms extends Record<string, any>> {\n private atoms: Map<keyof TAtoms, AtomStore<any>>;\n\n constructor(initialValues: TAtoms) {\n this.atoms = new Map();\n\n Object.entries(initialValues).forEach(([key, value]) => {\n this.atoms.set(key as keyof TAtoms, new AtomStore(value));\n });\n }\n\n public getAtomValue<TKey extends keyof TAtoms>(key: TKey): TAtoms[TKey] {\n const atomStore = this.atoms.get(key);\n if (!atomStore) {\n throw new Error(`Atom with key \"${String(key)}\" not found`);\n }\n return atomStore.getValue();\n }\n\n public setAtomValue<TKey extends keyof TAtoms>(\n key: TKey,\n value: TAtoms[TKey]\n ): void {\n const atomStore = this.atoms.get(key);\n if (!atomStore) {\n throw new Error(`Atom with key \"${String(key)}\" not found`);\n }\n atomStore.setValue(value);\n }\n\n public subscribeToAtom<TKey extends keyof TAtoms>(\n key: TKey,\n listener: (key: TKey, value: TAtoms[TKey]) => void\n ): Subscription {\n const atomStore = this.atoms.get(key);\n if (!atomStore) {\n throw new Error(`Atom with key \"${String(key)}\" not found`);\n }\n\n const atomListener = (value: TAtoms[TKey]) => {\n listener(key, value);\n };\n\n return atomStore.subscribe(atomListener);\n }\n\n public getAllAtomValues(): TAtoms {\n const result = {} as TAtoms;\n\n this.atoms.forEach((atomStore, key) => {\n result[key] = atomStore.getValue();\n });\n\n return result;\n }\n\n public updateAllAtoms(newAtoms: Partial<TAtoms>): void {\n Object.entries(newAtoms).forEach(([key, value]) => {\n const atomStore = this.atoms.get(key as keyof TAtoms);\n if (atomStore) {\n atomStore.setValue(value);\n }\n });\n }\n}\n"],"names":["AtomStore","value","listeners","constructor","initialValue","this","Set","getValue","setValue","newValue","Object","is","notifyListeners","forEach","listener","subscribe","add","unsubscribe","delete","atoms","initialValues","Map","entries","key","set","getAtomValue","atomStore","get","Error","String","setAtomValue","subscribeToAtom","getAllAtomValues","result","updateAllAtoms","newAtoms"],"mappings":"mBAEaA,EACHC,MACAC,UAER,WAAAC,CAAYC,GACVC,KAAKJ,MAAQG,EACbC,KAAKH,UAAY,IAAII,IAGhB,QAAAC,GACL,OAAOF,KAAKJ,MAGP,QAAAO,CAASC,GACVC,OAAOC,GAAGN,KAAKJ,MAAOQ,KAI1BJ,KAAKJ,MAAQQ,EACbJ,KAAKO,mBAGC,eAAAA,GACNP,KAAKH,UAAUW,SAASC,GAAaA,EAAST,KAAKJ,SAG9C,SAAAc,CAAUD,GACfT,KAAKH,UAAUc,IAAIF,GAMnB,MAAO,CACLG,YALkB,KAClBZ,KAAKH,UAAUgB,OAAOJ,EAAS,wDC5B3BK,MAER,WAAAhB,CAAYiB,GACVf,KAAKc,MAAQ,IAAIE,IAEjBX,OAAOY,QAAQF,GAAeP,SAAQ,EAAEU,EAAKtB,MAC3CI,KAAKc,MAAMK,IAAID,EAAqB,IAAIvB,EAAUC,GAAO,IAItD,YAAAwB,CAAwCF,GAC7C,MAAMG,EAAYrB,KAAKc,MAAMQ,IAAIJ,GACjC,IAAKG,EACH,MAAM,IAAIE,MAAM,kBAAkBC,OAAON,iBAE3C,OAAOG,EAAUnB,WAGZ,YAAAuB,CACLP,EACAtB,GAEA,MAAMyB,EAAYrB,KAAKc,MAAMQ,IAAIJ,GACjC,IAAKG,EACH,MAAM,IAAIE,MAAM,kBAAkBC,OAAON,iBAE3CG,EAAUlB,SAASP,GAGd,eAAA8B,CACLR,EACAT,GAEA,MAAMY,EAAYrB,KAAKc,MAAMQ,IAAIJ,GACjC,IAAKG,EACH,MAAM,IAAIE,MAAM,kBAAkBC,OAAON,iBAO3C,OAAOG,EAAUX,WAJKd,IACpBa,EAASS,EAAKtB,EAAM,IAMjB,gBAAA+B,GACL,MAAMC,EAAS,CAAY,EAM3B,OAJA5B,KAAKc,MAAMN,SAAQ,CAACa,EAAWH,KAC7BU,EAAOV,GAAOG,EAAUnB,UAAU,IAG7B0B,EAGF,cAAAC,CAAeC,GACpBzB,OAAOY,QAAQa,GAAUtB,SAAQ,EAAEU,EAAKtB,MACtC,MAAMyB,EAAYrB,KAAKc,MAAMQ,IAAIJ,GAC7BG,GACFA,EAAUlB,SAASP"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/atom-store.ts","../src/store.ts"],"sourcesContent":["import { AtomListener, Subscription } from \"./types\";\n\nexport class AtomStore<T> {\n private value: T;\n private listeners: Set<AtomListener>;\n\n constructor(initialValue: T) {\n this.value = initialValue;\n this.listeners = new Set();\n }\n\n public getValue(): T {\n return this.value;\n }\n\n public setValue(newValue: T): void {\n if (Object.is(this.value, newValue)) {\n return;\n }\n\n this.value = newValue;\n this.notifyListeners();\n }\n\n private notifyListeners(): void {\n this.listeners.forEach((listener) => listener());\n }\n\n public subscribe(listener: AtomListener): Subscription {\n this.listeners.add(listener);\n\n const unsubscribe = () => {\n this.listeners.delete(listener);\n };\n\n return {\n unsubscribe,\n };\n }\n}","import { AtomStore } from \"./atom-store\";\nimport { AtomListener, Subscription } from \"./types\";\n\nexport class ContextQueryStore<TAtoms extends Record<string, any>> {\n private atoms: Map<keyof TAtoms, AtomStore<any>>;\n\n constructor(initialValues: TAtoms) {\n this.atoms = new Map();\n\n Object.entries(initialValues).forEach(([key, value]) => {\n this.atoms.set(key as keyof TAtoms, new AtomStore(value));\n });\n }\n\n public getAtomValue<TKey extends keyof TAtoms>(key: TKey): TAtoms[TKey] {\n const atomStore = this.atoms.get(key);\n if (!atomStore) {\n throw new Error(`Atom with key \"${String(key)}\" not found`);\n }\n return atomStore.getValue();\n }\n\n public setAtomValue<TKey extends keyof TAtoms>(\n key: TKey,\n value: TAtoms[TKey]\n ): void {\n const atomStore = this.atoms.get(key);\n if (!atomStore) {\n throw new Error(`Atom with key \"${String(key)}\" not found`);\n }\n atomStore.setValue(value);\n }\n\n public subscribeToAtom<TKey extends keyof TAtoms>(\n key: TKey,\n listener: AtomListener\n ): Subscription {\n const atomStore = this.atoms.get(key);\n if (!atomStore) {\n throw new Error(`Atom with key \"${String(key)}\" not found`);\n }\n\n return atomStore.subscribe(listener);\n }\n\n public getAllAtomValues(): TAtoms {\n const result = {} as TAtoms;\n\n this.atoms.forEach((atomStore, key) => {\n result[key] = atomStore.getValue();\n });\n\n return result;\n }\n\n public updateAllAtoms(newAtoms: Partial<TAtoms>): void {\n Object.entries(newAtoms).forEach(([key, value]) => {\n const atomStore = this.atoms.get(key as keyof TAtoms);\n if (atomStore) {\n atomStore.setValue(value);\n }\n });\n }\n}\n"],"names":["AtomStore","value","listeners","constructor","initialValue","this","Set","getValue","setValue","newValue","Object","is","notifyListeners","forEach","listener","subscribe","add","unsubscribe","delete","atoms","initialValues","Map","entries","key","set","getAtomValue","atomStore","get","Error","String","setAtomValue","subscribeToAtom","getAllAtomValues","result","updateAllAtoms","newAtoms"],"mappings":"mBAEaA,EACHC,MACAC,UAER,WAAAC,CAAYC,GACVC,KAAKJ,MAAQG,EACbC,KAAKH,UAAY,IAAII,IAGhB,QAAAC,GACL,OAAOF,KAAKJ,MAGP,QAAAO,CAASC,GACVC,OAAOC,GAAGN,KAAKJ,MAAOQ,KAI1BJ,KAAKJ,MAAQQ,EACbJ,KAAKO,mBAGC,eAAAA,GACNP,KAAKH,UAAUW,SAASC,GAAaA,MAGhC,SAAAC,CAAUD,GACfT,KAAKH,UAAUc,IAAIF,GAMnB,MAAO,CACLG,YALkB,KAClBZ,KAAKH,UAAUgB,OAAOJ,EAAS,wDC5B3BK,MAER,WAAAhB,CAAYiB,GACVf,KAAKc,MAAQ,IAAIE,IAEjBX,OAAOY,QAAQF,GAAeP,SAAQ,EAAEU,EAAKtB,MAC3CI,KAAKc,MAAMK,IAAID,EAAqB,IAAIvB,EAAUC,GAAO,IAItD,YAAAwB,CAAwCF,GAC7C,MAAMG,EAAYrB,KAAKc,MAAMQ,IAAIJ,GACjC,IAAKG,EACH,MAAM,IAAIE,MAAM,kBAAkBC,OAAON,iBAE3C,OAAOG,EAAUnB,WAGZ,YAAAuB,CACLP,EACAtB,GAEA,MAAMyB,EAAYrB,KAAKc,MAAMQ,IAAIJ,GACjC,IAAKG,EACH,MAAM,IAAIE,MAAM,kBAAkBC,OAAON,iBAE3CG,EAAUlB,SAASP,GAGd,eAAA8B,CACLR,EACAT,GAEA,MAAMY,EAAYrB,KAAKc,MAAMQ,IAAIJ,GACjC,IAAKG,EACH,MAAM,IAAIE,MAAM,kBAAkBC,OAAON,iBAG3C,OAAOG,EAAUX,UAAUD,GAGtB,gBAAAkB,GACL,MAAMC,EAAS,CAAY,EAM3B,OAJA5B,KAAKc,MAAMN,SAAQ,CAACa,EAAWH,KAC7BU,EAAOV,GAAOG,EAAUnB,UAAU,IAG7B0B,EAGF,cAAAC,CAAeC,GACpBzB,OAAOY,QAAQa,GAAUtB,SAAQ,EAAEU,EAAKtB,MACtC,MAAMyB,EAAYrB,KAAKc,MAAMQ,IAAIJ,GAC7BG,GACFA,EAAUlB,SAASP"}
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- 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};
1
+ 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 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(e)}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};
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../src/atom-store.ts","../src/store.ts"],"sourcesContent":["import { AtomListener, Subscription } from \"./types\";\n\nexport class AtomStore<T> {\n private value: T;\n private listeners: Set<AtomListener<T>>;\n\n constructor(initialValue: T) {\n this.value = initialValue;\n this.listeners = new Set();\n }\n\n public getValue(): T {\n return this.value;\n }\n\n public setValue(newValue: T): void {\n if (Object.is(this.value, newValue)) {\n return;\n }\n\n this.value = newValue;\n this.notifyListeners();\n }\n\n private notifyListeners(): void {\n this.listeners.forEach((listener) => listener(this.value));\n }\n\n public subscribe(listener: AtomListener<T>): Subscription {\n this.listeners.add(listener);\n\n const unsubscribe = () => {\n this.listeners.delete(listener);\n };\n\n return {\n unsubscribe,\n };\n }\n}","import { AtomStore } from \"./atom-store\";\nimport { Subscription } from \"./types\";\n\nexport class ContextQueryStore<TAtoms extends Record<string, any>> {\n private atoms: Map<keyof TAtoms, AtomStore<any>>;\n\n constructor(initialValues: TAtoms) {\n this.atoms = new Map();\n\n Object.entries(initialValues).forEach(([key, value]) => {\n this.atoms.set(key as keyof TAtoms, new AtomStore(value));\n });\n }\n\n public getAtomValue<TKey extends keyof TAtoms>(key: TKey): TAtoms[TKey] {\n const atomStore = this.atoms.get(key);\n if (!atomStore) {\n throw new Error(`Atom with key \"${String(key)}\" not found`);\n }\n return atomStore.getValue();\n }\n\n public setAtomValue<TKey extends keyof TAtoms>(\n key: TKey,\n value: TAtoms[TKey]\n ): void {\n const atomStore = this.atoms.get(key);\n if (!atomStore) {\n throw new Error(`Atom with key \"${String(key)}\" not found`);\n }\n atomStore.setValue(value);\n }\n\n public subscribeToAtom<TKey extends keyof TAtoms>(\n key: TKey,\n listener: (key: TKey, value: TAtoms[TKey]) => void\n ): Subscription {\n const atomStore = this.atoms.get(key);\n if (!atomStore) {\n throw new Error(`Atom with key \"${String(key)}\" not found`);\n }\n\n const atomListener = (value: TAtoms[TKey]) => {\n listener(key, value);\n };\n\n return atomStore.subscribe(atomListener);\n }\n\n public getAllAtomValues(): TAtoms {\n const result = {} as TAtoms;\n\n this.atoms.forEach((atomStore, key) => {\n result[key] = atomStore.getValue();\n });\n\n return result;\n }\n\n public updateAllAtoms(newAtoms: Partial<TAtoms>): void {\n Object.entries(newAtoms).forEach(([key, value]) => {\n const atomStore = this.atoms.get(key as keyof TAtoms);\n if (atomStore) {\n atomStore.setValue(value);\n }\n });\n }\n}\n"],"names":["AtomStore","value","listeners","constructor","initialValue","this","Set","getValue","setValue","newValue","Object","is","notifyListeners","forEach","listener","subscribe","add","unsubscribe","delete","ContextQueryStore","atoms","initialValues","Map","entries","key","set","getAtomValue","atomStore","get","Error","String","setAtomValue","subscribeToAtom","getAllAtomValues","result","updateAllAtoms","newAtoms"],"mappings":"MAEaA,EACHC,MACAC,UAER,WAAAC,CAAYC,GACVC,KAAKJ,MAAQG,EACbC,KAAKH,UAAY,IAAII,IAGhB,QAAAC,GACL,OAAOF,KAAKJ,MAGP,QAAAO,CAASC,GACVC,OAAOC,GAAGN,KAAKJ,MAAOQ,KAI1BJ,KAAKJ,MAAQQ,EACbJ,KAAKO,mBAGC,eAAAA,GACNP,KAAKH,UAAUW,SAASC,GAAaA,EAAST,KAAKJ,SAG9C,SAAAc,CAAUD,GACfT,KAAKH,UAAUc,IAAIF,GAMnB,MAAO,CACLG,YALkB,KAClBZ,KAAKH,UAAUgB,OAAOJ,EAAS,UC7BxBK,EACHC,MAER,WAAAjB,CAAYkB,GACVhB,KAAKe,MAAQ,IAAIE,IAEjBZ,OAAOa,QAAQF,GAAeR,SAAQ,EAAEW,EAAKvB,MAC3CI,KAAKe,MAAMK,IAAID,EAAqB,IAAIxB,EAAUC,GAAO,IAItD,YAAAyB,CAAwCF,GAC7C,MAAMG,EAAYtB,KAAKe,MAAMQ,IAAIJ,GACjC,IAAKG,EACH,MAAM,IAAIE,MAAM,kBAAkBC,OAAON,iBAE3C,OAAOG,EAAUpB,WAGZ,YAAAwB,CACLP,EACAvB,GAEA,MAAM0B,EAAYtB,KAAKe,MAAMQ,IAAIJ,GACjC,IAAKG,EACH,MAAM,IAAIE,MAAM,kBAAkBC,OAAON,iBAE3CG,EAAUnB,SAASP,GAGd,eAAA+B,CACLR,EACAV,GAEA,MAAMa,EAAYtB,KAAKe,MAAMQ,IAAIJ,GACjC,IAAKG,EACH,MAAM,IAAIE,MAAM,kBAAkBC,OAAON,iBAO3C,OAAOG,EAAUZ,WAJKd,IACpBa,EAASU,EAAKvB,EAAM,IAMjB,gBAAAgC,GACL,MAAMC,EAAS,CAAY,EAM3B,OAJA7B,KAAKe,MAAMP,SAAQ,CAACc,EAAWH,KAC7BU,EAAOV,GAAOG,EAAUpB,UAAU,IAG7B2B,EAGF,cAAAC,CAAeC,GACpB1B,OAAOa,QAAQa,GAAUvB,SAAQ,EAAEW,EAAKvB,MACtC,MAAM0B,EAAYtB,KAAKe,MAAMQ,IAAIJ,GAC7BG,GACFA,EAAUnB,SAASP"}
1
+ {"version":3,"file":"index.mjs","sources":["../src/atom-store.ts","../src/store.ts"],"sourcesContent":["import { AtomListener, Subscription } from \"./types\";\n\nexport class AtomStore<T> {\n private value: T;\n private listeners: Set<AtomListener>;\n\n constructor(initialValue: T) {\n this.value = initialValue;\n this.listeners = new Set();\n }\n\n public getValue(): T {\n return this.value;\n }\n\n public setValue(newValue: T): void {\n if (Object.is(this.value, newValue)) {\n return;\n }\n\n this.value = newValue;\n this.notifyListeners();\n }\n\n private notifyListeners(): void {\n this.listeners.forEach((listener) => listener());\n }\n\n public subscribe(listener: AtomListener): Subscription {\n this.listeners.add(listener);\n\n const unsubscribe = () => {\n this.listeners.delete(listener);\n };\n\n return {\n unsubscribe,\n };\n }\n}","import { AtomStore } from \"./atom-store\";\nimport { AtomListener, Subscription } from \"./types\";\n\nexport class ContextQueryStore<TAtoms extends Record<string, any>> {\n private atoms: Map<keyof TAtoms, AtomStore<any>>;\n\n constructor(initialValues: TAtoms) {\n this.atoms = new Map();\n\n Object.entries(initialValues).forEach(([key, value]) => {\n this.atoms.set(key as keyof TAtoms, new AtomStore(value));\n });\n }\n\n public getAtomValue<TKey extends keyof TAtoms>(key: TKey): TAtoms[TKey] {\n const atomStore = this.atoms.get(key);\n if (!atomStore) {\n throw new Error(`Atom with key \"${String(key)}\" not found`);\n }\n return atomStore.getValue();\n }\n\n public setAtomValue<TKey extends keyof TAtoms>(\n key: TKey,\n value: TAtoms[TKey]\n ): void {\n const atomStore = this.atoms.get(key);\n if (!atomStore) {\n throw new Error(`Atom with key \"${String(key)}\" not found`);\n }\n atomStore.setValue(value);\n }\n\n public subscribeToAtom<TKey extends keyof TAtoms>(\n key: TKey,\n listener: AtomListener\n ): Subscription {\n const atomStore = this.atoms.get(key);\n if (!atomStore) {\n throw new Error(`Atom with key \"${String(key)}\" not found`);\n }\n\n return atomStore.subscribe(listener);\n }\n\n public getAllAtomValues(): TAtoms {\n const result = {} as TAtoms;\n\n this.atoms.forEach((atomStore, key) => {\n result[key] = atomStore.getValue();\n });\n\n return result;\n }\n\n public updateAllAtoms(newAtoms: Partial<TAtoms>): void {\n Object.entries(newAtoms).forEach(([key, value]) => {\n const atomStore = this.atoms.get(key as keyof TAtoms);\n if (atomStore) {\n atomStore.setValue(value);\n }\n });\n }\n}\n"],"names":["AtomStore","value","listeners","constructor","initialValue","this","Set","getValue","setValue","newValue","Object","is","notifyListeners","forEach","listener","subscribe","add","unsubscribe","delete","ContextQueryStore","atoms","initialValues","Map","entries","key","set","getAtomValue","atomStore","get","Error","String","setAtomValue","subscribeToAtom","getAllAtomValues","result","updateAllAtoms","newAtoms"],"mappings":"MAEaA,EACHC,MACAC,UAER,WAAAC,CAAYC,GACVC,KAAKJ,MAAQG,EACbC,KAAKH,UAAY,IAAII,IAGhB,QAAAC,GACL,OAAOF,KAAKJ,MAGP,QAAAO,CAASC,GACVC,OAAOC,GAAGN,KAAKJ,MAAOQ,KAI1BJ,KAAKJ,MAAQQ,EACbJ,KAAKO,mBAGC,eAAAA,GACNP,KAAKH,UAAUW,SAASC,GAAaA,MAGhC,SAAAC,CAAUD,GACfT,KAAKH,UAAUc,IAAIF,GAMnB,MAAO,CACLG,YALkB,KAClBZ,KAAKH,UAAUgB,OAAOJ,EAAS,UC7BxBK,EACHC,MAER,WAAAjB,CAAYkB,GACVhB,KAAKe,MAAQ,IAAIE,IAEjBZ,OAAOa,QAAQF,GAAeR,SAAQ,EAAEW,EAAKvB,MAC3CI,KAAKe,MAAMK,IAAID,EAAqB,IAAIxB,EAAUC,GAAO,IAItD,YAAAyB,CAAwCF,GAC7C,MAAMG,EAAYtB,KAAKe,MAAMQ,IAAIJ,GACjC,IAAKG,EACH,MAAM,IAAIE,MAAM,kBAAkBC,OAAON,iBAE3C,OAAOG,EAAUpB,WAGZ,YAAAwB,CACLP,EACAvB,GAEA,MAAM0B,EAAYtB,KAAKe,MAAMQ,IAAIJ,GACjC,IAAKG,EACH,MAAM,IAAIE,MAAM,kBAAkBC,OAAON,iBAE3CG,EAAUnB,SAASP,GAGd,eAAA+B,CACLR,EACAV,GAEA,MAAMa,EAAYtB,KAAKe,MAAMQ,IAAIJ,GACjC,IAAKG,EACH,MAAM,IAAIE,MAAM,kBAAkBC,OAAON,iBAG3C,OAAOG,EAAUZ,UAAUD,GAGtB,gBAAAmB,GACL,MAAMC,EAAS,CAAY,EAM3B,OAJA7B,KAAKe,MAAMP,SAAQ,CAACc,EAAWH,KAC7BU,EAAOV,GAAOG,EAAUpB,UAAU,IAG7B2B,EAGF,cAAAC,CAAeC,GACpB1B,OAAOa,QAAQa,GAAUvB,SAAQ,EAAEW,EAAKvB,MACtC,MAAM0B,EAAYtB,KAAKe,MAAMQ,IAAIJ,GAC7BG,GACFA,EAAUnB,SAASP"}
package/dist/store.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- import { Subscription } from "./types";
1
+ import { AtomListener, Subscription } from "./types";
2
2
  export declare class ContextQueryStore<TAtoms extends Record<string, any>> {
3
3
  private atoms;
4
4
  constructor(initialValues: TAtoms);
5
5
  getAtomValue<TKey extends keyof TAtoms>(key: TKey): TAtoms[TKey];
6
6
  setAtomValue<TKey extends keyof TAtoms>(key: TKey, value: TAtoms[TKey]): void;
7
- subscribeToAtom<TKey extends keyof TAtoms>(key: TKey, listener: (key: TKey, value: TAtoms[TKey]) => void): Subscription;
7
+ subscribeToAtom<TKey extends keyof TAtoms>(key: TKey, listener: AtomListener): Subscription;
8
8
  getAllAtomValues(): TAtoms;
9
9
  updateAllAtoms(newAtoms: Partial<TAtoms>): void;
10
10
  }
package/dist/types.d.ts CHANGED
@@ -2,7 +2,7 @@ export type Subscription = {
2
2
  unsubscribe: () => void;
3
3
  };
4
4
  export type Listener<T> = (value: T) => void;
5
- export type AtomListener<T> = (value: T) => void;
5
+ export type AtomListener = () => void;
6
6
  export type Updater<TAtoms> = (atoms: TAtoms) => Partial<TAtoms>;
7
7
  export type TStateImpl = Record<string, any>;
8
8
  export type TAtoms = Record<string, any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@context-query/core",
3
- "version": "0.3.2-beta.1",
3
+ "version": "0.3.2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "scripts": {