@context-query/core 0.2.1 → 0.3.0-beta.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@context-query/core",
3
- "version": "0.2.1",
3
+ "version": "0.3.0-beta.1",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "scripts": {
package/dist/index.esm.js DELETED
@@ -1,2 +0,0 @@
1
- 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};
2
- //# sourceMappingURL=index.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.esm.js","sources":["../src/store.ts"],"sourcesContent":["import { Listener, Subscription, TStateImpl } from \"./types\";\n\nexport class ContextQueryStore<TState extends TStateImpl> {\n private state: TState;\n private listeners: Map<keyof TState, Set<Listener<any>>>;\n\n constructor(initialState: TState) {\n this.state = initialState;\n this.listeners = new Map();\n }\n\n public getState(): TState {\n return this.state;\n }\n\n public getStateByKey<TKey extends keyof TState>(key: TKey): TState[TKey] {\n return this.state[key];\n }\n\n public updateState<TKey extends keyof TState>(state: TState): void {\n const prevState = { ...this.state };\n this.state = { ...state };\n const keys = Object.keys(state) as TKey[];\n\n keys.forEach((key: TKey) => {\n if (!Object.is(prevState[key], this.state[key])) {\n this.notifyListeners(key);\n }\n });\n }\n\n public setState<TKey extends keyof TState>(\n key: TKey,\n value: TState[TKey]\n ): void {\n if (Object.is(this.state[key], value)) {\n return;\n }\n\n this.state = { ...this.state, [key]: value };\n\n this.notifyListeners(key);\n }\n\n private notifyListeners<TKey extends keyof TState>(key: TKey) {\n const listeners = this.listeners.get(key);\n if (listeners) {\n const value = this.state[key];\n listeners.forEach((listener) => listener(value));\n }\n }\n\n public subscribe<TKey extends keyof TState>(\n key: TKey,\n listener: (key: TKey, value: TState[TKey]) => void\n ): Subscription {\n const keyListener = (value: TState[TKey]) => {\n listener(key, value);\n };\n\n if (!this.listeners.has(key)) {\n this.listeners.set(key, new Set());\n }\n\n this.listeners.get(key)!.add(keyListener);\n\n const unsubscribe = () => {\n const keyListeners = this.listeners.get(key);\n if (keyListeners) {\n keyListeners.delete(keyListener);\n if (keyListeners.size === 0) {\n this.listeners.delete(key);\n }\n }\n };\n\n return {\n unsubscribe,\n };\n }\n}\n"],"names":["ContextQueryStore","state","listeners","constructor","initialState","this","Map","getState","getStateByKey","key","updateState","prevState","Object","keys","forEach","is","notifyListeners","setState","value","get","listener","subscribe","keyListener","has","set","Set","add","unsubscribe","keyListeners","delete","size"],"mappings":"MAEaA,EACHC,MACAC,UAER,WAAAC,CAAYC,GACVC,KAAKJ,MAAQG,EACbC,KAAKH,UAAY,IAAII,IAGhB,QAAAC,GACL,OAAOF,KAAKJ,MAGP,aAAAO,CAAyCC,GAC9C,OAAOJ,KAAKJ,MAAMQ,GAGb,WAAAC,CAAuCT,GAC5C,MAAMU,EAAY,IAAKN,KAAKJ,OAC5BI,KAAKJ,MAAQ,IAAKA,GACLW,OAAOC,KAAKZ,GAEpBa,SAASL,IACPG,OAAOG,GAAGJ,EAAUF,GAAMJ,KAAKJ,MAAMQ,KACxCJ,KAAKW,gBAAgBP,MAKpB,QAAAQ,CACLR,EACAS,GAEIN,OAAOG,GAAGV,KAAKJ,MAAMQ,GAAMS,KAI/Bb,KAAKJ,MAAQ,IAAKI,KAAKJ,MAAOQ,CAACA,GAAMS,GAErCb,KAAKW,gBAAgBP,IAGf,eAAAO,CAA2CP,GACjD,MAAMP,EAAYG,KAAKH,UAAUiB,IAAIV,GACrC,GAAIP,EAAW,CACb,MAAMgB,EAAQb,KAAKJ,MAAMQ,GACzBP,EAAUY,SAASM,GAAaA,EAASF,MAItC,SAAAG,CACLZ,EACAW,GAEA,MAAME,EAAeJ,IACnBE,EAASX,EAAKS,EAAM,EAGjBb,KAAKH,UAAUqB,IAAId,IACtBJ,KAAKH,UAAUsB,IAAIf,EAAK,IAAIgB,KAG9BpB,KAAKH,UAAUiB,IAAIV,GAAMiB,IAAIJ,GAY7B,MAAO,CACLK,YAXkB,KAClB,MAAMC,EAAevB,KAAKH,UAAUiB,IAAIV,GACpCmB,IACFA,EAAaC,OAAOP,GACM,IAAtBM,EAAaE,MACfzB,KAAKH,UAAU2B,OAAOpB"}
package/dist/index.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";exports.ContextQueryStore=class{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))}}}};
2
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":["../src/store.ts"],"sourcesContent":["import { Listener, Subscription, TStateImpl } from \"./types\";\n\nexport class ContextQueryStore<TState extends TStateImpl> {\n private state: TState;\n private listeners: Map<keyof TState, Set<Listener<any>>>;\n\n constructor(initialState: TState) {\n this.state = initialState;\n this.listeners = new Map();\n }\n\n public getState(): TState {\n return this.state;\n }\n\n public getStateByKey<TKey extends keyof TState>(key: TKey): TState[TKey] {\n return this.state[key];\n }\n\n public updateState<TKey extends keyof TState>(state: TState): void {\n const prevState = { ...this.state };\n this.state = { ...state };\n const keys = Object.keys(state) as TKey[];\n\n keys.forEach((key: TKey) => {\n if (!Object.is(prevState[key], this.state[key])) {\n this.notifyListeners(key);\n }\n });\n }\n\n public setState<TKey extends keyof TState>(\n key: TKey,\n value: TState[TKey]\n ): void {\n if (Object.is(this.state[key], value)) {\n return;\n }\n\n this.state = { ...this.state, [key]: value };\n\n this.notifyListeners(key);\n }\n\n private notifyListeners<TKey extends keyof TState>(key: TKey) {\n const listeners = this.listeners.get(key);\n if (listeners) {\n const value = this.state[key];\n listeners.forEach((listener) => listener(value));\n }\n }\n\n public subscribe<TKey extends keyof TState>(\n key: TKey,\n listener: (key: TKey, value: TState[TKey]) => void\n ): Subscription {\n const keyListener = (value: TState[TKey]) => {\n listener(key, value);\n };\n\n if (!this.listeners.has(key)) {\n this.listeners.set(key, new Set());\n }\n\n this.listeners.get(key)!.add(keyListener);\n\n const unsubscribe = () => {\n const keyListeners = this.listeners.get(key);\n if (keyListeners) {\n keyListeners.delete(keyListener);\n if (keyListeners.size === 0) {\n this.listeners.delete(key);\n }\n }\n };\n\n return {\n unsubscribe,\n };\n }\n}\n"],"names":["state","listeners","constructor","initialState","this","Map","getState","getStateByKey","key","updateState","prevState","Object","keys","forEach","is","notifyListeners","setState","value","get","listener","subscribe","keyListener","has","set","Set","add","unsubscribe","keyListeners","delete","size"],"mappings":"6CAGUA,MACAC,UAER,WAAAC,CAAYC,GACVC,KAAKJ,MAAQG,EACbC,KAAKH,UAAY,IAAII,IAGhB,QAAAC,GACL,OAAOF,KAAKJ,MAGP,aAAAO,CAAyCC,GAC9C,OAAOJ,KAAKJ,MAAMQ,GAGb,WAAAC,CAAuCT,GAC5C,MAAMU,EAAY,IAAKN,KAAKJ,OAC5BI,KAAKJ,MAAQ,IAAKA,GACLW,OAAOC,KAAKZ,GAEpBa,SAASL,IACPG,OAAOG,GAAGJ,EAAUF,GAAMJ,KAAKJ,MAAMQ,KACxCJ,KAAKW,gBAAgBP,MAKpB,QAAAQ,CACLR,EACAS,GAEIN,OAAOG,GAAGV,KAAKJ,MAAMQ,GAAMS,KAI/Bb,KAAKJ,MAAQ,IAAKI,KAAKJ,MAAOQ,CAACA,GAAMS,GAErCb,KAAKW,gBAAgBP,IAGf,eAAAO,CAA2CP,GACjD,MAAMP,EAAYG,KAAKH,UAAUiB,IAAIV,GACrC,GAAIP,EAAW,CACb,MAAMgB,EAAQb,KAAKJ,MAAMQ,GACzBP,EAAUY,SAASM,GAAaA,EAASF,MAItC,SAAAG,CACLZ,EACAW,GAEA,MAAME,EAAeJ,IACnBE,EAASX,EAAKS,EAAM,EAGjBb,KAAKH,UAAUqB,IAAId,IACtBJ,KAAKH,UAAUsB,IAAIf,EAAK,IAAIgB,KAG9BpB,KAAKH,UAAUiB,IAAIV,GAAMiB,IAAIJ,GAY7B,MAAO,CACLK,YAXkB,KAClB,MAAMC,EAAevB,KAAKH,UAAUiB,IAAIV,GACpCmB,IACFA,EAAaC,OAAOP,GACM,IAAtBM,EAAaE,MACfzB,KAAKH,UAAU2B,OAAOpB"}