shelving 1.68.0 → 1.68.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/index.js +3 -0
- package/package.json +3 -2
- package/react/index.d.ts +1 -0
- package/react/index.js +1 -0
- package/react/useCache.d.ts +23 -3
- package/react/useCache.js +23 -3
- package/react/useDocument.d.ts +4 -1
- package/react/useDocument.js +2 -2
- package/react/useQuery.d.ts +4 -1
- package/react/useQuery.js +2 -2
package/index.js
CHANGED
|
@@ -19,5 +19,8 @@ export * from "./update/index.js";
|
|
|
19
19
|
export * from "./util/index.js";
|
|
20
20
|
// Integrations.
|
|
21
21
|
// export * from "./react/index.js"; // Not exported.
|
|
22
|
+
// export * from "./firestore/client/index.js"; // Not exported.
|
|
23
|
+
// export * from "./firestore/lite/index.js"; // Not exported.
|
|
24
|
+
// export * from "./firestore/server/index.js"; // Not exported.
|
|
22
25
|
// Testing.
|
|
23
26
|
// export * from "./test/index.js"; // Not exported.
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"state-management",
|
|
12
12
|
"query-builder"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.68.
|
|
14
|
+
"version": "1.68.1",
|
|
15
15
|
"repository": "https://github.com/dhoulb/shelving",
|
|
16
16
|
"author": "Dave Houlbrooke <dave@shax.com>",
|
|
17
17
|
"license": "0BSD",
|
|
@@ -29,11 +29,12 @@
|
|
|
29
29
|
"./firestore/lite": "./firestore/lite/index.js",
|
|
30
30
|
"./firestore/server": "./firestore/server/index.js",
|
|
31
31
|
"./markup": "./markup/index.js",
|
|
32
|
+
"./observe": "./observe/index.js",
|
|
32
33
|
"./provider": "./provider/index.js",
|
|
33
34
|
"./query": "./query/index.js",
|
|
34
35
|
"./react": "./react/index.js",
|
|
35
36
|
"./schema": "./schema/index.js",
|
|
36
|
-
"./
|
|
37
|
+
"./state": "./state/index.js",
|
|
37
38
|
"./test": "./test/index.js",
|
|
38
39
|
"./update": "./update/index.js",
|
|
39
40
|
"./util": "./util/index.js"
|
package/react/index.d.ts
CHANGED
package/react/index.js
CHANGED
package/react/useCache.d.ts
CHANGED
|
@@ -15,12 +15,32 @@ export declare class CacheController<T> {
|
|
|
15
15
|
/**
|
|
16
16
|
* Default cache
|
|
17
17
|
* - This is a flexible generic cache intended to be the default.
|
|
18
|
-
* - Use this cache unless
|
|
18
|
+
* - Use this cache unless you want to cache a completely independent set of items without interference.
|
|
19
19
|
*/
|
|
20
20
|
export declare const CACHE: CacheController<any>;
|
|
21
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* Use a global cache in a component.
|
|
23
|
+
* - Throws an error if used outside of `<Cache>`
|
|
24
|
+
*/
|
|
22
25
|
export declare const useCache: () => Map<string, any>;
|
|
23
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* Component that provides a global cache to its children.
|
|
28
|
+
*
|
|
29
|
+
* Note: If mounted globally this cache will bloat over time, so you need a strategy to clear or reset the cache occasionally.
|
|
30
|
+
*
|
|
31
|
+
* A good strategy is to wrap a separate `<Cache>` around each page of your app.
|
|
32
|
+
* This means the cache can only grow to the size of each page and the memory is released when the user navigates to a new page.
|
|
33
|
+
* You might need to use `<Cache key="something unique to the page">` to ensure the cache component is destroyed and remounted for each page.
|
|
34
|
+
*
|
|
35
|
+
* Put a `<Suspense>` boundary _inside_ `<Cache>`
|
|
36
|
+
* - This prevents promises being thrown up through the cache causing it to be destroyed.
|
|
37
|
+
* - When the promise resolves and the render is tried again the data would not exist (because the cache was destroyed).
|
|
38
|
+
* - This will cause an infinite loading loop.
|
|
39
|
+
*
|
|
40
|
+
* Put your error boundary _outside_ your `<Cache>`
|
|
41
|
+
* - The error being thrown up through the cache causes it to be destroyed.
|
|
42
|
+
* - This means when the uses tells the error boundary to try again (if supported) all data on the page will be retried.
|
|
43
|
+
*/
|
|
24
44
|
export declare const Cache: ({ children }: {
|
|
25
45
|
children: React.ReactNode;
|
|
26
46
|
}) => React.ReactElement | null;
|
package/react/useCache.js
CHANGED
|
@@ -27,10 +27,30 @@ const _reduceMap = (previous) => previous || new Map();
|
|
|
27
27
|
/**
|
|
28
28
|
* Default cache
|
|
29
29
|
* - This is a flexible generic cache intended to be the default.
|
|
30
|
-
* - Use this cache unless
|
|
30
|
+
* - Use this cache unless you want to cache a completely independent set of items without interference.
|
|
31
31
|
*/
|
|
32
32
|
export const CACHE = new CacheController(); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
33
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* Use a global cache in a component.
|
|
35
|
+
* - Throws an error if used outside of `<Cache>`
|
|
36
|
+
*/
|
|
34
37
|
export const useCache = CACHE.useCache;
|
|
35
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
* Component that provides a global cache to its children.
|
|
40
|
+
*
|
|
41
|
+
* Note: If mounted globally this cache will bloat over time, so you need a strategy to clear or reset the cache occasionally.
|
|
42
|
+
*
|
|
43
|
+
* A good strategy is to wrap a separate `<Cache>` around each page of your app.
|
|
44
|
+
* This means the cache can only grow to the size of each page and the memory is released when the user navigates to a new page.
|
|
45
|
+
* You might need to use `<Cache key="something unique to the page">` to ensure the cache component is destroyed and remounted for each page.
|
|
46
|
+
*
|
|
47
|
+
* Put a `<Suspense>` boundary _inside_ `<Cache>`
|
|
48
|
+
* - This prevents promises being thrown up through the cache causing it to be destroyed.
|
|
49
|
+
* - When the promise resolves and the render is tried again the data would not exist (because the cache was destroyed).
|
|
50
|
+
* - This will cause an infinite loading loop.
|
|
51
|
+
*
|
|
52
|
+
* Put your error boundary _outside_ your `<Cache>`
|
|
53
|
+
* - The error being thrown up through the cache causes it to be destroyed.
|
|
54
|
+
* - This means when the uses tells the error boundary to try again (if supported) all data on the page will be retried.
|
|
55
|
+
*/
|
|
36
56
|
export const Cache = CACHE.Cache;
|
package/react/useDocument.d.ts
CHANGED
|
@@ -23,6 +23,9 @@ export declare class DocumentState<T extends Data> extends State<OptionalEntity<
|
|
|
23
23
|
protected _addFirstObserver(): void;
|
|
24
24
|
protected _removeLastObserver(): void;
|
|
25
25
|
}
|
|
26
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* Use a document in a React component.
|
|
28
|
+
* - Uses the default cache, so will error if not used inside `<Cache>`
|
|
29
|
+
*/
|
|
27
30
|
export declare function useDocument<T extends Data>(ref: DocumentReference<T>): DocumentState<T>;
|
|
28
31
|
export declare function useDocument<T extends Data>(ref?: DocumentReference<T>): DocumentState<T> | undefined;
|
package/react/useDocument.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { reduceMapItem } from "../util/map.js";
|
|
2
|
-
import { getDocumentData
|
|
2
|
+
import { getDocumentData } from "../db/Reference.js";
|
|
3
3
|
import { CacheProvider } from "../provider/CacheProvider.js";
|
|
4
4
|
import { findSourceProvider } from "../provider/ThroughProvider.js";
|
|
5
5
|
import { State } from "../state/State.js";
|
|
@@ -75,7 +75,7 @@ export class DocumentState extends State {
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
/** Reuse the previous `DocumentState` or create a new one. */
|
|
78
|
-
const _reduceDocumentState = (existing, ref) =>
|
|
78
|
+
const _reduceDocumentState = (existing, ref) => existing || new DocumentState(ref);
|
|
79
79
|
export function useDocument(ref) {
|
|
80
80
|
const cache = useCache();
|
|
81
81
|
const state = ref ? reduceMapItem(cache, ref.toString(), _reduceDocumentState, ref) : undefined;
|
package/react/useQuery.d.ts
CHANGED
|
@@ -40,6 +40,9 @@ export declare class QueryState<T extends Data> extends State<Entities<T>> {
|
|
|
40
40
|
*/
|
|
41
41
|
readonly loadMore: () => Promise<void>;
|
|
42
42
|
}
|
|
43
|
-
/**
|
|
43
|
+
/**
|
|
44
|
+
* Use a query in a React component.
|
|
45
|
+
* - Uses the default cache, so will error if not used inside `<Cache>`
|
|
46
|
+
*/
|
|
44
47
|
export declare function useQuery<T extends Data>(ref: QueryReference<T>): QueryState<T>;
|
|
45
48
|
export declare function useQuery<T extends Data>(ref?: QueryReference<T>): QueryState<T> | undefined;
|
package/react/useQuery.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { reduceMapItem } from "../util/map.js";
|
|
2
|
-
import { getQueryFirstData, getQueryFirstValue
|
|
2
|
+
import { getQueryFirstData, getQueryFirstValue } from "../db/Reference.js";
|
|
3
3
|
import { CacheProvider } from "../provider/CacheProvider.js";
|
|
4
4
|
import { findSourceProvider } from "../provider/ThroughProvider.js";
|
|
5
5
|
import { State } from "../state/State.js";
|
|
@@ -120,7 +120,7 @@ export class QueryState extends State {
|
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
/** Reuse the previous `QueryState` or create a new one. */
|
|
123
|
-
const _reduceQueryState = (existing, ref) =>
|
|
123
|
+
const _reduceQueryState = (existing, ref) => existing || new QueryState(ref);
|
|
124
124
|
export function useQuery(ref) {
|
|
125
125
|
const cache = useCache();
|
|
126
126
|
const state = ref ? reduceMapItem(cache, ref.toString(), _reduceQueryState, ref) : undefined;
|