cross-state 0.33.6 → 0.33.8
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/README.md +171 -3
- package/dist/cjs/cache.cjs +2 -1
- package/dist/cjs/cache.cjs.map +1 -1
- package/dist/cjs/store.cjs +36 -13
- package/dist/cjs/store.cjs.map +1 -1
- package/dist/cjs/useCache.cjs +2 -8
- package/dist/cjs/useCache.cjs.map +1 -1
- package/dist/es/cache.mjs +2 -1
- package/dist/es/cache.mjs.map +1 -1
- package/dist/es/store.mjs +36 -13
- package/dist/es/store.mjs.map +1 -1
- package/dist/es/useCache.mjs +2 -8
- package/dist/es/useCache.mjs.map +1 -1
- package/dist/types/react/useCache.d.ts +0 -5
- package/dist/types/react/useStore.d.ts +5 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,18 +5,186 @@ State library for frontend and backend. With React bindings.
|
|
|
5
5
|
|
|
6
6
|
# Getting started
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
## Install
|
|
9
9
|
|
|
10
10
|
```
|
|
11
11
|
npm install cross-state
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
+
## The basics
|
|
15
|
+
|
|
16
|
+
cross-state provides a number of tools to manage state in your application.
|
|
17
|
+
The most important building blocks are: stores (`createStore`) for global state and caches (`createCache`) for e.g. wrapping api calls.
|
|
18
|
+
They can be used in any JavaScript environment and are not tied to any specific framework.
|
|
19
|
+
React bindings are provided and can be used to easily integrate cross-state in your ui.
|
|
20
|
+
|
|
21
|
+
### React bindings
|
|
22
|
+
|
|
23
|
+
You can use cross-state with React by importing the respective hooks - e.g. `useStore`.
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
import { useStore } from 'cross-state/react';
|
|
27
|
+
|
|
28
|
+
function Counter() {
|
|
29
|
+
const counter = useStore(store, (state) => state.counter); // with or without selector
|
|
30
|
+
return <div>{counter}</div>;
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Or you can register the react bindings with the Store and Cache prototypes.
|
|
35
|
+
|
|
36
|
+
```tsx
|
|
37
|
+
// Somewhere in your app setup
|
|
38
|
+
import 'cross-state/react/register';
|
|
39
|
+
|
|
40
|
+
function Counter() {
|
|
41
|
+
const counter = store.useStore((state) => state.counter); // with or without selector
|
|
42
|
+
return <div>{counter}</div>;
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Stores
|
|
47
|
+
|
|
14
48
|
### Create a store
|
|
15
49
|
|
|
16
|
-
|
|
17
|
-
import { createStore } from 'cross-state';
|
|
50
|
+
The state can be any value, e.g. a number, an object or an array.
|
|
18
51
|
|
|
52
|
+
```ts
|
|
19
53
|
export const store = createStore({
|
|
20
54
|
counter: 0,
|
|
21
55
|
});
|
|
22
56
|
```
|
|
57
|
+
|
|
58
|
+
### Get the current state
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
const state = store.get();
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Update the store
|
|
65
|
+
|
|
66
|
+
Pass in a new state or a function that updates the current state.
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
store.set((state) => ({
|
|
70
|
+
counter: state.counter + 1,
|
|
71
|
+
}));
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Subscribe to changes
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
const cancel = store.subscribe((state) => {
|
|
78
|
+
console.log('New state:', state);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// Later, to unsubscribe
|
|
82
|
+
cancel();
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Use the store in a React component
|
|
86
|
+
|
|
87
|
+
```tsx
|
|
88
|
+
function Counter() {
|
|
89
|
+
const state = store.useStore(); // without selector - be careful with this, as it will rerender on every state change
|
|
90
|
+
const counter1 = store.useStore((state) => state.counter); // with selector - will only rerender when the selected value changes
|
|
91
|
+
const counter2 = store.useStore('counter'); // with string selector
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<div>
|
|
95
|
+
<div>{state.counter}</div>
|
|
96
|
+
<div>{counter1}</div>
|
|
97
|
+
<div>{counter2}</div>
|
|
98
|
+
</div>
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Use the store in a React component with an update function
|
|
104
|
+
|
|
105
|
+
```tsx
|
|
106
|
+
function Counter() {
|
|
107
|
+
const [value, setValue] = store.useProp('counter');
|
|
108
|
+
|
|
109
|
+
return (
|
|
110
|
+
<div>
|
|
111
|
+
<div>{value}</div>
|
|
112
|
+
<button onClick={() => setValue((value) => value + 1)}>Increment</button>
|
|
113
|
+
</div>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Caches
|
|
119
|
+
|
|
120
|
+
### Create a cache
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
export const user = createCache(
|
|
124
|
+
async (org: string, id: string) => {
|
|
125
|
+
const response = await fetch(`https://api.example.com/${org}/${id}`);
|
|
126
|
+
const user: User = response.json();
|
|
127
|
+
return user;
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
invalidateAfter: { minutes: 10 }, // automatically invalidate the cache after 10 minutes
|
|
131
|
+
},
|
|
132
|
+
);
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
- `invalidateAfter: Duration | ((state: ValueState<T> | ErrorState) => Duration | null) | null;` - automatically invalidate the cache after a certain duration. You can also provide a function that returns a duration or null based on the current state of the cache:
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
export const cache = createCache([...],
|
|
139
|
+
{
|
|
140
|
+
invalidateAfter(({ status, value, error }) => {
|
|
141
|
+
if (status === 'error') {
|
|
142
|
+
return { minutes: 5 };
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return value.expiresAt - Date.now();
|
|
146
|
+
}),
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
);
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Use the cache
|
|
153
|
+
|
|
154
|
+
```ts
|
|
155
|
+
const data = await cache('users', '123');
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Use the cache in a React component
|
|
159
|
+
|
|
160
|
+
```tsx
|
|
161
|
+
function User({ org, id }: { org: string; id: string }) {
|
|
162
|
+
const [user, error, isLoading] = user(org, id).useCache();
|
|
163
|
+
|
|
164
|
+
if (isLoading) {
|
|
165
|
+
return <div>Loading...</div>;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (error) {
|
|
169
|
+
return <div>Error: {error.message}</div>;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return <div>{user.name}</div>;
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Cache without parameters
|
|
177
|
+
|
|
178
|
+
When the cache does not have parameters or only optional parameters, you can use the cache without the parantheses.
|
|
179
|
+
|
|
180
|
+
```ts
|
|
181
|
+
const cache = createCache(async () => {
|
|
182
|
+
return await fetch('https://api.example.com');
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
const data = await cache.useCache(); // equivalent to cache().useCache()
|
|
186
|
+
|
|
187
|
+
// or in a React component
|
|
188
|
+
|
|
189
|
+
const [data, error, isLoading] = cache.useCache();
|
|
190
|
+
```
|
package/dist/cjs/cache.cjs
CHANGED
|
@@ -122,6 +122,7 @@ class Cache extends store.Store {
|
|
|
122
122
|
store.autobind(Cache);
|
|
123
123
|
this.watchPromise();
|
|
124
124
|
this.watchFocus();
|
|
125
|
+
this.state.addEffect(() => this.subscribe(() => void 0));
|
|
125
126
|
}
|
|
126
127
|
get({ update = "whenStale", backgroundUpdate = false } = {}) {
|
|
127
128
|
var _a, _b;
|
|
@@ -276,7 +277,7 @@ class Cache extends store.Store {
|
|
|
276
277
|
document.removeEventListener("visibilitychange", onFocus);
|
|
277
278
|
return;
|
|
278
279
|
}
|
|
279
|
-
if (!document.hidden) {
|
|
280
|
+
if (!document.hidden && !that.state.get().isConnected) {
|
|
280
281
|
that.invalidate();
|
|
281
282
|
}
|
|
282
283
|
};
|
package/dist/cjs/cache.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.cjs","sources":["../../src/lib/instanceCache.ts","../../src/core/resourceGroup.ts","../../src/core/cache.ts"],"sourcesContent":["import { hash } from './hash';\n\nexport class InstanceCache<Args extends any[], T extends object> {\n private cache = new Map<string, { t: number; ref?: T; weakRef: WeakRef<T> }>();\n\n private interval = this.cacheTime\n ? setInterval(() => this.cleanup(), Math.max(this.cacheTime / 10, 1))\n : undefined;\n\n constructor(public readonly factory: (...args: Args) => T, public readonly cacheTime?: number) {}\n\n cleanup() {\n const cutoff = this.now() - (this.cacheTime ?? 0);\n\n for (const [key, entry] of this.cache.entries()) {\n if (entry.ref && entry.t <= cutoff) {\n delete entry.ref;\n }\n\n if (!entry.ref && !entry.weakRef?.deref()) {\n this.cache.delete(key);\n }\n }\n }\n\n get(...args: Args) {\n const key = hash(args);\n let entry = this.cache.get(key);\n let value = entry?.ref ?? entry?.weakRef?.deref();\n\n if (!entry || !value) {\n value = this.factory(...args);\n entry = {\n t: this.now(),\n ref: value,\n weakRef: new WeakRef(value),\n };\n\n this.cache.set(key, entry);\n } else {\n entry.t = this.now();\n entry.ref ??= value;\n }\n\n return value;\n }\n\n values() {\n return [...this.cache.values()]\n .map((entry) => entry.ref ?? entry.weakRef?.deref())\n .filter((value): value is T => !!value);\n }\n\n stop() {\n if (this.interval) {\n clearInterval(this.interval);\n }\n }\n\n stats() {\n return {\n count: this.cache.size,\n withRef: [...this.cache.values()].filter((x) => !!x.ref).length,\n withWeakRef: [...this.cache.values()].filter((x) => !!x.weakRef?.deref()).length,\n };\n }\n\n private now() {\n return performance.now();\n }\n}\n","import { autobind } from '@lib/autobind';\n\nexport interface Resource {\n invalidateAll(): void;\n clearAll(): void;\n}\n\nexport class ResourceGroup {\n private refMap = new WeakMap<Resource, WeakRef<Resource>>();\n\n private refSet = new Set<WeakRef<Resource>>();\n\n constructor(public readonly name?: string) {\n autobind(ResourceGroup);\n }\n\n add(resource: Resource) {\n const ref = new WeakRef(resource);\n this.refMap.set(resource, ref);\n this.refSet.add(ref);\n }\n\n delete(resource: Resource) {\n const ref = this.refMap.get(resource);\n if (ref) {\n this.refMap.delete(resource);\n this.refSet.delete(ref);\n }\n }\n\n invalidateAll() {\n for (const ref of this.refSet) {\n const resource = ref.deref();\n if (resource) {\n resource.invalidateAll();\n } else {\n this.refSet.delete(ref);\n }\n }\n }\n\n clearAll() {\n for (const ref of this.refSet) {\n const resource = ref.deref();\n if (resource) {\n resource.clearAll();\n } else {\n this.refSet.delete(ref);\n }\n }\n }\n}\n\nexport const allResources = /* @__PURE__ */ new ResourceGroup();\n\nexport function createResourceGroup(name?: string) {\n return new ResourceGroup(name);\n}\n","import { autobind } from '@lib/autobind';\nimport type { CacheState, ErrorState, ValueState } from '@lib/cacheState';\nimport { calcDuration } from '@lib/calcDuration';\nimport { calculatedValue } from '@lib/calculatedValue';\nimport { InstanceCache } from '@lib/instanceCache';\nimport { makeSelector } from '@lib/makeSelector';\nimport { type MaybePromise } from '@lib/maybePromise';\nimport type { Path, Value } from '@lib/path';\nimport { PromiseWithState } from '@lib/promiseWithState';\nimport type { Duration, Selector } from './commonTypes';\nimport { allResources, type ResourceGroup } from './resourceGroup';\nimport { Store, createStore, type Calculate, type StoreOptions } from './store';\n\nexport interface CacheGetOptions {\n update?: 'whenMissing' | 'whenStale' | 'force';\n backgroundUpdate?: boolean;\n}\n\nexport interface CacheFunction<T, Args extends any[] = []> {\n (...args: Args): Promise<T> | Calculate<Promise<T>>;\n}\n\nexport interface CacheOptions<T> extends StoreOptions {\n invalidateAfter?: Duration | ((state: ValueState<T> | ErrorState) => Duration | null) | null;\n invalidateOnWindowFocus?: boolean;\n invalidateOnActivation?: boolean;\n clearOnInvalidate?: boolean;\n clearUnusedAfter?: Duration | null;\n resourceGroup?: ResourceGroup | ResourceGroup[];\n}\n\nexport class Cache<T> extends Store<Promise<T>> {\n readonly state = createStore<CacheState<T>>({\n status: 'pending',\n isStale: true,\n isUpdating: false,\n isConnected: false,\n });\n\n protected stalePromise?: Promise<T>;\n\n protected invalidationTimer?: ReturnType<typeof setTimeout>;\n\n constructor(\n getter: Calculate<Promise<T>>,\n public readonly options: CacheOptions<T> = {},\n public readonly derivedFromCache?: {\n cache: Cache<any>;\n selectors: (Selector<any, any> | Path<any>)[];\n },\n _call?: (...args: any[]) => any,\n ) {\n super(getter, options, undefined, _call);\n autobind(Cache);\n\n this.watchPromise();\n this.watchFocus();\n }\n\n get({ update = 'whenStale', backgroundUpdate = false }: CacheGetOptions = {}) {\n const promise = this.calculatedValue?.value;\n const stalePromise = this.stalePromise;\n\n if (\n (update === 'whenMissing' && !promise && !stalePromise) ||\n (update === 'whenStale' && !promise) ||\n update === 'force'\n ) {\n this.calculatedValue?.stop();\n this.calculatedValue = calculatedValue(this, this.notify);\n this.notify();\n\n if ((!promise && !stalePromise) || !backgroundUpdate) {\n return super.get();\n }\n }\n\n if (!promise || (stalePromise && backgroundUpdate)) {\n return stalePromise!;\n }\n\n return promise;\n }\n\n updateValue(value: MaybePromise<T>) {\n this.set(PromiseWithState.resolve(value));\n }\n\n updateError(error: unknown) {\n this.set(PromiseWithState.reject(error));\n }\n\n invalidate(recursive?: boolean) {\n const { clearOnInvalidate } = this.options;\n\n if (clearOnInvalidate) {\n return this.clear(recursive);\n }\n\n const { status, isStale, isUpdating } = this.state.get();\n if (status !== 'pending' && !isStale && !isUpdating) {\n this.stalePromise = this.calculatedValue?.value;\n }\n\n this.state.set((state) => ({\n ...state,\n isStale: true,\n isUpdating: false,\n }));\n\n super.invalidate(recursive);\n }\n\n clear(recursive?: boolean): void {\n this.state.set({\n status: 'pending',\n isStale: true,\n isUpdating: false,\n isConnected: false,\n });\n delete this.stalePromise;\n\n super.invalidate(recursive);\n }\n\n mapValue<S>(selector: Selector<T, S>): Cache<S>;\n\n mapValue<P extends Path<T>>(selector: P): Cache<Value<T, P>>;\n\n mapValue<S>(_selector: Selector<T, S> | Path<any>): Cache<S> {\n const selector = makeSelector(_selector);\n const derivedFromCache = {\n cache: this.derivedFromCache ? this.derivedFromCache.cache : this,\n selectors: this.derivedFromCache\n ? [...this.derivedFromCache.selectors, _selector]\n : [_selector],\n };\n\n return new Cache(\n async ({ use }) => {\n const value = await use(this);\n return selector(value);\n },\n {},\n derivedFromCache,\n );\n }\n\n protected watchPromise() {\n this.subscribe(\n async (promise) => {\n if (promise instanceof PromiseWithState) {\n this.state.set((state) => ({\n ...promise.state,\n isStale: false,\n isUpdating: false,\n isConnected: state.isConnected,\n }));\n\n delete this.stalePromise;\n this.setTimers();\n return;\n }\n\n this.state.set((state) => ({\n ...state,\n isUpdating: true,\n }));\n\n this.setTimers();\n\n try {\n const value = await promise;\n\n if (promise !== this.calculatedValue?.value) {\n return;\n }\n\n this.state.set((state) => ({\n status: 'value',\n value,\n isStale: false,\n isUpdating: false,\n isConnected: state.isConnected,\n }));\n delete this.stalePromise;\n this.setTimers();\n } catch (error) {\n if (promise !== this.calculatedValue?.value) {\n return;\n }\n\n this.state.set((state) => ({\n status: 'error',\n error,\n isStale: false,\n isUpdating: false,\n isConnected: state.isConnected,\n }));\n delete this.stalePromise;\n this.setTimers();\n }\n },\n { passive: true },\n );\n }\n\n protected setTimers() {\n if (this.invalidationTimer) {\n clearTimeout(this.invalidationTimer);\n }\n this.invalidationTimer = undefined;\n\n const state = this.state.get();\n let { invalidateAfter } = this.options;\n const ref = new WeakRef(this);\n\n if (state.status === 'pending') {\n return;\n }\n\n if (invalidateAfter instanceof Function) {\n invalidateAfter = invalidateAfter(state);\n }\n\n if (invalidateAfter !== null && invalidateAfter !== undefined) {\n this.invalidationTimer = setTimeout(\n () => ref?.deref()?.invalidate(),\n calcDuration(invalidateAfter),\n );\n }\n }\n\n protected watchFocus() {\n const { invalidateOnWindowFocus } = this.options;\n\n if (\n !invalidateOnWindowFocus ||\n typeof document === 'undefined' ||\n typeof document.addEventListener === 'undefined'\n ) {\n return;\n }\n\n const ref = new WeakRef(this);\n\n const onFocus = () => {\n const that = ref?.deref();\n if (!that) {\n document.removeEventListener('visibilitychange', onFocus);\n return;\n }\n\n if (!document.hidden) {\n that.invalidate();\n }\n };\n\n document.addEventListener('visibilitychange', onFocus);\n }\n}\n\ntype CreateReturnType<T, Args extends any[]> = {\n (...args: Args): Cache<T>;\n invalidateAll: () => void;\n clearAll: () => void;\n} & ([] extends Args ? Cache<T> : {});\n\nfunction create<T, Args extends any[] = []>(\n cacheFunction: CacheFunction<T, Args>,\n options?: CacheOptions<T>,\n): CreateReturnType<T, Args> {\n options = { ...createCache.defaultOptions, ...options };\n const { clearUnusedAfter, resourceGroup } = options ?? {};\n\n let baseInstance: CreateReturnType<T, Args> & Cache<T>;\n\n const instanceCache = new InstanceCache<Args, Cache<T>>(\n (...args: Args): Cache<T> => {\n if (args.length === 0 && baseInstance) {\n return baseInstance;\n }\n\n return new Cache((helpers) => {\n const result = cacheFunction.apply(helpers, args);\n\n if (result instanceof Function) {\n return result(helpers);\n }\n\n return result;\n }, options);\n },\n clearUnusedAfter ? calcDuration(clearUnusedAfter) : undefined,\n );\n\n const get = (...args: Args) => {\n return instanceCache.get(...args);\n };\n\n const invalidateAll = () => {\n for (const instance of instanceCache.values()) {\n instance.invalidate();\n }\n };\n\n const clearAll = () => {\n for (const instance of instanceCache.values()) {\n instance.clear();\n }\n };\n\n baseInstance = Object.assign(\n new Cache(\n (helpers) => {\n const result = cacheFunction.apply(helpers);\n\n if (result instanceof Function) {\n return result(helpers);\n }\n\n return result;\n },\n options,\n undefined,\n get,\n ),\n {\n invalidateAll,\n clearAll,\n },\n ) as CreateReturnType<T, Args> & Cache<T>;\n\n const groups = Array.isArray(resourceGroup)\n ? resourceGroup\n : resourceGroup\n ? [resourceGroup]\n : [];\n for (const group of groups.concat(allResources)) {\n group.add(baseInstance);\n }\n\n get(...([] as any));\n\n return baseInstance;\n}\n\nexport const createCache = /* @__PURE__ */ Object.assign(create, {\n defaultOptions: {\n invalidateOnWindowFocus: true,\n invalidateOnActivation: true,\n clearUnusedAfter: { days: 1 },\n retain: { seconds: 1 },\n } as CacheOptions<unknown>,\n});\n"],"names":["hash","autobind","Store","createStore","calculatedValue","PromiseWithState","makeSelector","calcDuration"],"mappings":";;;AAEO,MAAM,cAAoD;AAAA,EAO/D,YAA4B,SAA+C,WAAoB;AAAnE,SAAA,UAAA;AAA+C,SAAA,YAAA;AANnE,SAAA,4BAAY;AAEpB,SAAQ,WAAW,KAAK,YACpB,YAAY,MAAM,KAAK,QAAW,GAAA,KAAK,IAAI,KAAK,YAAY,IAAI,CAAC,CAAC,IAClE;AAAA,EAE4F;AAAA,EAEhG,UAAU;;AACR,UAAM,SAAS,KAAK,IAAI,KAAK,KAAK,aAAa;AAE/C,eAAW,CAAC,KAAK,KAAK,KAAK,KAAK,MAAM,WAAW;AAC/C,UAAI,MAAM,OAAO,MAAM,KAAK,QAAQ;AAClC,eAAO,MAAM;AAAA,MACf;AAEA,UAAI,CAAC,MAAM,OAAO,GAAC,WAAM,YAAN,mBAAe,UAAS;AACpC,aAAA,MAAM,OAAO,GAAG;AAAA,MACvB;AAAA,IACF;AAAA,EACF;AAAA,EAEA,OAAO,MAAY;;AACX,UAAA,MAAMA,WAAK,IAAI;AACrB,QAAI,QAAQ,KAAK,MAAM,IAAI,GAAG;AAC9B,QAAI,SAAQ,+BAAO,UAAO,oCAAO,YAAP,mBAAgB;AAEtC,QAAA,CAAC,SAAS,CAAC,OAAO;AACZ,cAAA,KAAK,QAAQ,GAAG,IAAI;AACpB,cAAA;AAAA,QACN,GAAG,KAAK,IAAI;AAAA,QACZ,KAAK;AAAA,QACL,SAAS,IAAI,QAAQ,KAAK;AAAA,MAAA;AAGvB,WAAA,MAAM,IAAI,KAAK,KAAK;AAAA,IAAA,OACpB;AACC,YAAA,IAAI,KAAK;AACf,YAAM,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EAAA;AAGhD,QAAA,MAAM,IAAI,SAAe;AACtB,WAAA,cAAc,IAAI,GAAG,IAAI;AAAA,EAAA;AAGlC,QAAM,gBAAgB,MAAM;AACf,eAAA,YAAY,cAAc,UAAU;AAC7C,eAAS,WAAW;AAAA,IACtB;AAAA,EAAA;AAGF,QAAM,WAAW,MAAM;AACV,eAAA,YAAY,cAAc,UAAU;AAC7C,eAAS,MAAM;AAAA,IACjB;AAAA,EAAA;AAGF,iBAAe,OAAO;AAAA,IACpB,IAAI;AAAA,MACF,CAAC,YAAY;AACL,cAAA,SAAS,cAAc,MAAM,OAAO;AAE1C,YAAI,kBAAkB,UAAU;AAC9B,iBAAO,OAAO,OAAO;AAAA,QACvB;AAEO,eAAA;AAAA,MACT;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,IACF;AAAA,EAAA;AAGI,QAAA,SAAS,MAAM,QAAQ,aAAa,IACtC,gBACA,gBACE,CAAC,aAAa,IACd;AACN,aAAW,SAAS,OAAO,OAAO,YAAY,GAAG;AAC/C,UAAM,IAAI,YAAY;AAAA,EACxB;AAEI,MAAA,GAAI,CAAA,CAAU;AAEX,SAAA;AACT;AAEa,MAAA,cAAqC,uBAAA,OAAO,QAAQ;AAAA,EAC/D,gBAAgB;AAAA,IACd,yBAAyB;AAAA,IACzB,wBAAwB;AAAA,IACxB,kBAAkB,EAAE,MAAM,EAAE;AAAA,IAC5B,QAAQ,EAAE,SAAS,EAAE;AAAA,EACvB;AACF,CAAC;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"cache.cjs","sources":["../../src/lib/instanceCache.ts","../../src/core/resourceGroup.ts","../../src/core/cache.ts"],"sourcesContent":["import { hash } from './hash';\n\nexport class InstanceCache<Args extends any[], T extends object> {\n private cache = new Map<string, { t: number; ref?: T; weakRef: WeakRef<T> }>();\n\n private interval = this.cacheTime\n ? setInterval(() => this.cleanup(), Math.max(this.cacheTime / 10, 1))\n : undefined;\n\n constructor(public readonly factory: (...args: Args) => T, public readonly cacheTime?: number) {}\n\n cleanup() {\n const cutoff = this.now() - (this.cacheTime ?? 0);\n\n for (const [key, entry] of this.cache.entries()) {\n if (entry.ref && entry.t <= cutoff) {\n delete entry.ref;\n }\n\n if (!entry.ref && !entry.weakRef?.deref()) {\n this.cache.delete(key);\n }\n }\n }\n\n get(...args: Args) {\n const key = hash(args);\n let entry = this.cache.get(key);\n let value = entry?.ref ?? entry?.weakRef?.deref();\n\n if (!entry || !value) {\n value = this.factory(...args);\n entry = {\n t: this.now(),\n ref: value,\n weakRef: new WeakRef(value),\n };\n\n this.cache.set(key, entry);\n } else {\n entry.t = this.now();\n entry.ref ??= value;\n }\n\n return value;\n }\n\n values() {\n return [...this.cache.values()]\n .map((entry) => entry.ref ?? entry.weakRef?.deref())\n .filter((value): value is T => !!value);\n }\n\n stop() {\n if (this.interval) {\n clearInterval(this.interval);\n }\n }\n\n stats() {\n return {\n count: this.cache.size,\n withRef: [...this.cache.values()].filter((x) => !!x.ref).length,\n withWeakRef: [...this.cache.values()].filter((x) => !!x.weakRef?.deref()).length,\n };\n }\n\n private now() {\n return performance.now();\n }\n}\n","import { autobind } from '@lib/autobind';\n\nexport interface Resource {\n invalidateAll(): void;\n clearAll(): void;\n}\n\nexport class ResourceGroup {\n private refMap = new WeakMap<Resource, WeakRef<Resource>>();\n\n private refSet = new Set<WeakRef<Resource>>();\n\n constructor(public readonly name?: string) {\n autobind(ResourceGroup);\n }\n\n add(resource: Resource) {\n const ref = new WeakRef(resource);\n this.refMap.set(resource, ref);\n this.refSet.add(ref);\n }\n\n delete(resource: Resource) {\n const ref = this.refMap.get(resource);\n if (ref) {\n this.refMap.delete(resource);\n this.refSet.delete(ref);\n }\n }\n\n invalidateAll() {\n for (const ref of this.refSet) {\n const resource = ref.deref();\n if (resource) {\n resource.invalidateAll();\n } else {\n this.refSet.delete(ref);\n }\n }\n }\n\n clearAll() {\n for (const ref of this.refSet) {\n const resource = ref.deref();\n if (resource) {\n resource.clearAll();\n } else {\n this.refSet.delete(ref);\n }\n }\n }\n}\n\nexport const allResources = /* @__PURE__ */ new ResourceGroup();\n\nexport function createResourceGroup(name?: string) {\n return new ResourceGroup(name);\n}\n","import { autobind } from '@lib/autobind';\nimport type { CacheState, ErrorState, ValueState } from '@lib/cacheState';\nimport { calcDuration } from '@lib/calcDuration';\nimport { calculatedValue } from '@lib/calculatedValue';\nimport { InstanceCache } from '@lib/instanceCache';\nimport { makeSelector } from '@lib/makeSelector';\nimport { type MaybePromise } from '@lib/maybePromise';\nimport type { Path, Value } from '@lib/path';\nimport { PromiseWithState } from '@lib/promiseWithState';\nimport type { Duration, Selector } from './commonTypes';\nimport { allResources, type ResourceGroup } from './resourceGroup';\nimport { Store, createStore, type Calculate, type StoreOptions } from './store';\n\nexport interface CacheGetOptions {\n update?: 'whenMissing' | 'whenStale' | 'force';\n backgroundUpdate?: boolean;\n}\n\nexport interface CacheFunction<T, Args extends any[] = []> {\n (...args: Args): Promise<T> | Calculate<Promise<T>>;\n}\n\nexport interface CacheOptions<T> extends StoreOptions {\n invalidateAfter?: Duration | ((state: ValueState<T> | ErrorState) => Duration | null) | null;\n invalidateOnWindowFocus?: boolean;\n invalidateOnActivation?: boolean;\n clearOnInvalidate?: boolean;\n clearUnusedAfter?: Duration | null;\n resourceGroup?: ResourceGroup | ResourceGroup[];\n}\n\nexport class Cache<T> extends Store<Promise<T>> {\n readonly state = createStore<CacheState<T>>({\n status: 'pending',\n isStale: true,\n isUpdating: false,\n isConnected: false,\n });\n\n protected stalePromise?: Promise<T>;\n\n protected invalidationTimer?: ReturnType<typeof setTimeout>;\n\n constructor(\n getter: Calculate<Promise<T>>,\n public readonly options: CacheOptions<T> = {},\n public readonly derivedFromCache?: {\n cache: Cache<any>;\n selectors: (Selector<any, any> | Path<any>)[];\n },\n _call?: (...args: any[]) => any,\n ) {\n super(getter, options, undefined, _call);\n autobind(Cache);\n\n this.watchPromise();\n this.watchFocus();\n\n this.state.addEffect(() => this.subscribe(() => undefined));\n }\n\n get({ update = 'whenStale', backgroundUpdate = false }: CacheGetOptions = {}) {\n const promise = this.calculatedValue?.value;\n const stalePromise = this.stalePromise;\n\n if (\n (update === 'whenMissing' && !promise && !stalePromise) ||\n (update === 'whenStale' && !promise) ||\n update === 'force'\n ) {\n this.calculatedValue?.stop();\n this.calculatedValue = calculatedValue(this, this.notify);\n this.notify();\n\n if ((!promise && !stalePromise) || !backgroundUpdate) {\n return super.get();\n }\n }\n\n if (!promise || (stalePromise && backgroundUpdate)) {\n return stalePromise!;\n }\n\n return promise;\n }\n\n updateValue(value: MaybePromise<T>) {\n this.set(PromiseWithState.resolve(value));\n }\n\n updateError(error: unknown) {\n this.set(PromiseWithState.reject(error));\n }\n\n invalidate(recursive?: boolean) {\n const { clearOnInvalidate } = this.options;\n\n if (clearOnInvalidate) {\n return this.clear(recursive);\n }\n\n const { status, isStale, isUpdating } = this.state.get();\n if (status !== 'pending' && !isStale && !isUpdating) {\n this.stalePromise = this.calculatedValue?.value;\n }\n\n this.state.set((state) => ({\n ...state,\n isStale: true,\n isUpdating: false,\n }));\n\n super.invalidate(recursive);\n }\n\n clear(recursive?: boolean): void {\n this.state.set({\n status: 'pending',\n isStale: true,\n isUpdating: false,\n isConnected: false,\n });\n delete this.stalePromise;\n\n super.invalidate(recursive);\n }\n\n mapValue<S>(selector: Selector<T, S>): Cache<S>;\n\n mapValue<P extends Path<T>>(selector: P): Cache<Value<T, P>>;\n\n mapValue<S>(_selector: Selector<T, S> | Path<any>): Cache<S> {\n const selector = makeSelector(_selector);\n const derivedFromCache = {\n cache: this.derivedFromCache ? this.derivedFromCache.cache : this,\n selectors: this.derivedFromCache\n ? [...this.derivedFromCache.selectors, _selector]\n : [_selector],\n };\n\n return new Cache(\n async ({ use }) => {\n const value = await use(this);\n return selector(value);\n },\n {},\n derivedFromCache,\n );\n }\n\n protected watchPromise() {\n this.subscribe(\n async (promise) => {\n if (promise instanceof PromiseWithState) {\n this.state.set((state) => ({\n ...promise.state,\n isStale: false,\n isUpdating: false,\n isConnected: state.isConnected,\n }));\n\n delete this.stalePromise;\n this.setTimers();\n return;\n }\n\n this.state.set((state) => ({\n ...state,\n isUpdating: true,\n }));\n\n this.setTimers();\n\n try {\n const value = await promise;\n\n if (promise !== this.calculatedValue?.value) {\n return;\n }\n\n this.state.set((state) => ({\n status: 'value',\n value,\n isStale: false,\n isUpdating: false,\n isConnected: state.isConnected,\n }));\n delete this.stalePromise;\n this.setTimers();\n } catch (error) {\n if (promise !== this.calculatedValue?.value) {\n return;\n }\n\n this.state.set((state) => ({\n status: 'error',\n error,\n isStale: false,\n isUpdating: false,\n isConnected: state.isConnected,\n }));\n delete this.stalePromise;\n this.setTimers();\n }\n },\n { passive: true },\n );\n }\n\n protected setTimers() {\n if (this.invalidationTimer) {\n clearTimeout(this.invalidationTimer);\n }\n this.invalidationTimer = undefined;\n\n const state = this.state.get();\n let { invalidateAfter } = this.options;\n const ref = new WeakRef(this);\n\n if (state.status === 'pending') {\n return;\n }\n\n if (invalidateAfter instanceof Function) {\n invalidateAfter = invalidateAfter(state);\n }\n\n if (invalidateAfter !== null && invalidateAfter !== undefined) {\n this.invalidationTimer = setTimeout(\n () => ref?.deref()?.invalidate(),\n calcDuration(invalidateAfter),\n );\n }\n }\n\n protected watchFocus() {\n const { invalidateOnWindowFocus } = this.options;\n\n if (\n !invalidateOnWindowFocus ||\n typeof document === 'undefined' ||\n typeof document.addEventListener === 'undefined'\n ) {\n return;\n }\n\n const ref = new WeakRef(this);\n\n const onFocus = () => {\n const that = ref?.deref();\n if (!that) {\n document.removeEventListener('visibilitychange', onFocus);\n return;\n }\n\n if (!document.hidden && !that.state.get().isConnected) {\n that.invalidate();\n }\n };\n\n document.addEventListener('visibilitychange', onFocus);\n }\n}\n\ntype CreateReturnType<T, Args extends any[]> = {\n (...args: Args): Cache<T>;\n invalidateAll: () => void;\n clearAll: () => void;\n} & ([] extends Args ? Cache<T> : {});\n\nfunction create<T, Args extends any[] = []>(\n cacheFunction: CacheFunction<T, Args>,\n options?: CacheOptions<T>,\n): CreateReturnType<T, Args> {\n options = { ...createCache.defaultOptions, ...options };\n const { clearUnusedAfter, resourceGroup } = options ?? {};\n\n let baseInstance: CreateReturnType<T, Args> & Cache<T>;\n\n const instanceCache = new InstanceCache<Args, Cache<T>>(\n (...args: Args): Cache<T> => {\n if (args.length === 0 && baseInstance) {\n return baseInstance;\n }\n\n return new Cache((helpers) => {\n const result = cacheFunction.apply(helpers, args);\n\n if (result instanceof Function) {\n return result(helpers);\n }\n\n return result;\n }, options);\n },\n clearUnusedAfter ? calcDuration(clearUnusedAfter) : undefined,\n );\n\n const get = (...args: Args) => {\n return instanceCache.get(...args);\n };\n\n const invalidateAll = () => {\n for (const instance of instanceCache.values()) {\n instance.invalidate();\n }\n };\n\n const clearAll = () => {\n for (const instance of instanceCache.values()) {\n instance.clear();\n }\n };\n\n baseInstance = Object.assign(\n new Cache(\n (helpers) => {\n const result = cacheFunction.apply(helpers);\n\n if (result instanceof Function) {\n return result(helpers);\n }\n\n return result;\n },\n options,\n undefined,\n get,\n ),\n {\n invalidateAll,\n clearAll,\n },\n ) as CreateReturnType<T, Args> & Cache<T>;\n\n const groups = Array.isArray(resourceGroup)\n ? resourceGroup\n : resourceGroup\n ? [resourceGroup]\n : [];\n for (const group of groups.concat(allResources)) {\n group.add(baseInstance);\n }\n\n get(...([] as any));\n\n return baseInstance;\n}\n\nexport const createCache = /* @__PURE__ */ Object.assign(create, {\n defaultOptions: {\n invalidateOnWindowFocus: true,\n invalidateOnActivation: true,\n clearUnusedAfter: { days: 1 },\n retain: { seconds: 1 },\n } as CacheOptions<unknown>,\n});\n"],"names":["hash","autobind","Store","createStore","calculatedValue","PromiseWithState","makeSelector","calcDuration"],"mappings":";;;AAEO,MAAM,cAAoD;AAAA,EAO/D,YAA4B,SAA+C,WAAoB;AAAnE,SAAA,UAAA;AAA+C,SAAA,YAAA;AANnE,SAAA,4BAAY;AAEpB,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AA;AAGF,iBAAe,OAAO;AAAA,IACpB,IAAI;AAAA,MACF,CAAC,YAAY;AACL,cAAA,SAAS,cAAc,MAAM,OAAO;AAE1C,YAAI,kBAAkB,UAAU;AAC9B,iBAAO,OAAO,OAAO;AAAA,QACvB;AAEO,eAAA;AAAA,MACT;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,IACF;AAAA,EAAA;AAGI,QAAA,SAAS,MAAM,QAAQ,aAAa,IACtC,gBACA,gBACE,CAAC,aAAa,IACd;AACN,aAAW,SAAS,OAAO,OAAO,YAAY,GAAG;AAC/C,UAAM,IAAI,YAAY;AAAA,EACxB;AAEI,MAAA,GAAI,CAAA,CAAU;AAEX,SAAA;AACT;AAEa,MAAA,cAAqC,uBAAA,OAAO,QAAQ;AAAA,EAC/D,gBAAgB;AAAA,IACd,yBAAyB;AAAA,IACzB,wBAAwB;AAAA,IACxB,kBAAkB,EAAE,MAAM,EAAE;AAAA,IAC5B,QAAQ,EAAE,SAAS,EAAE;AAAA,EACvB;AACF,CAAC;;;;;;;"}
|
package/dist/cjs/store.cjs
CHANGED
|
@@ -194,11 +194,11 @@ function calculatedValue(store, notify) {
|
|
|
194
194
|
let value;
|
|
195
195
|
const whenConnected = new Deferred();
|
|
196
196
|
const whenExecuted = new Deferred();
|
|
197
|
-
let
|
|
197
|
+
let connection;
|
|
198
198
|
const q = queue();
|
|
199
199
|
q(() => whenExecuted);
|
|
200
200
|
const cancelEffect = store.addEffect(() => {
|
|
201
|
-
if (
|
|
201
|
+
if (connection) {
|
|
202
202
|
store.invalidate();
|
|
203
203
|
return;
|
|
204
204
|
}
|
|
@@ -207,13 +207,18 @@ function calculatedValue(store, notify) {
|
|
|
207
207
|
dep.on();
|
|
208
208
|
}
|
|
209
209
|
return () => {
|
|
210
|
+
var _a;
|
|
210
211
|
active = false;
|
|
211
212
|
for (const dep of deps) {
|
|
212
213
|
dep.off();
|
|
213
214
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
215
|
+
if (connection) {
|
|
216
|
+
connection.active = false;
|
|
217
|
+
(_a = connection.cancel) == null ? void 0 : _a.call(connection);
|
|
218
|
+
q.clear();
|
|
219
|
+
if ("state" in store) {
|
|
220
|
+
store.state.set("isConnected", false);
|
|
221
|
+
}
|
|
217
222
|
}
|
|
218
223
|
};
|
|
219
224
|
});
|
|
@@ -233,34 +238,40 @@ function calculatedValue(store, notify) {
|
|
|
233
238
|
}
|
|
234
239
|
return value2;
|
|
235
240
|
}
|
|
236
|
-
async function connect(
|
|
241
|
+
async function connect(createConnection) {
|
|
237
242
|
if (!active) {
|
|
238
243
|
return;
|
|
239
244
|
}
|
|
240
245
|
const actions = {
|
|
241
246
|
set(value2) {
|
|
242
|
-
q(() => {
|
|
247
|
+
(connection == null ? void 0 : connection.active) && q(() => {
|
|
243
248
|
store.set(value2);
|
|
244
249
|
});
|
|
245
250
|
},
|
|
246
251
|
updateValue(update) {
|
|
247
|
-
q(async () => {
|
|
252
|
+
(connection == null ? void 0 : connection.active) && q(async () => {
|
|
248
253
|
if (update instanceof Function) {
|
|
249
254
|
update = update(await value);
|
|
250
255
|
}
|
|
251
256
|
if (update instanceof Promise) {
|
|
252
257
|
update = await update;
|
|
253
258
|
}
|
|
259
|
+
if (!(connection == null ? void 0 : connection.active)) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
254
262
|
value = PromiseWithState.resolve(update);
|
|
255
263
|
notify();
|
|
256
264
|
});
|
|
257
265
|
},
|
|
258
266
|
updateError(error) {
|
|
259
|
-
q(() => {
|
|
267
|
+
(connection == null ? void 0 : connection.active) && q(() => {
|
|
260
268
|
store.set(Promise.reject(error));
|
|
261
269
|
});
|
|
262
270
|
},
|
|
263
271
|
updateIsConnected(isConnected) {
|
|
272
|
+
if (!(connection == null ? void 0 : connection.active)) {
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
264
275
|
if (isConnected) {
|
|
265
276
|
whenConnected.resolve();
|
|
266
277
|
}
|
|
@@ -271,10 +282,14 @@ function calculatedValue(store, notify) {
|
|
|
271
282
|
});
|
|
272
283
|
},
|
|
273
284
|
close() {
|
|
274
|
-
store.invalidate();
|
|
285
|
+
(connection == null ? void 0 : connection.active) && store.invalidate();
|
|
275
286
|
}
|
|
276
287
|
};
|
|
277
|
-
|
|
288
|
+
connection = { active: true };
|
|
289
|
+
connection.cancel = createConnection(actions);
|
|
290
|
+
if (!connection.active) {
|
|
291
|
+
connection.cancel();
|
|
292
|
+
}
|
|
278
293
|
return whenConnected;
|
|
279
294
|
}
|
|
280
295
|
value = store.getter instanceof Function ? store.getter({ use, connect }) : store.getter;
|
|
@@ -293,9 +308,12 @@ function calculatedValue(store, notify) {
|
|
|
293
308
|
}
|
|
294
309
|
}
|
|
295
310
|
function stop() {
|
|
311
|
+
var _a;
|
|
296
312
|
cancelEffect();
|
|
297
|
-
|
|
298
|
-
|
|
313
|
+
if (connection) {
|
|
314
|
+
connection.active = false;
|
|
315
|
+
(_a = connection.cancel) == null ? void 0 : _a.call(connection);
|
|
316
|
+
q.clear();
|
|
299
317
|
whenConnected.reject();
|
|
300
318
|
whenExecuted.reject();
|
|
301
319
|
} else {
|
|
@@ -645,9 +663,13 @@ class Store extends Callable {
|
|
|
645
663
|
debounce: debounceOption,
|
|
646
664
|
equals = deepEqual
|
|
647
665
|
} = options ?? {};
|
|
666
|
+
let isSetup = false;
|
|
648
667
|
let previousValue;
|
|
649
668
|
let innerListener = () => {
|
|
650
669
|
var _a;
|
|
670
|
+
if (!isSetup) {
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
651
673
|
const value = passive ? this.calculatedValue : { value: this.get() };
|
|
652
674
|
if (!value) {
|
|
653
675
|
return;
|
|
@@ -672,6 +694,7 @@ class Store extends Callable {
|
|
|
672
694
|
if (!passive) {
|
|
673
695
|
this.onSubscribe();
|
|
674
696
|
}
|
|
697
|
+
isSetup = true;
|
|
675
698
|
if (runNow) {
|
|
676
699
|
innerListener();
|
|
677
700
|
} else {
|