shelving 1.68.1 → 1.68.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.
- package/package.json +1 -1
- package/react/useDocument.d.ts +2 -1
- package/react/useDocument.js +18 -16
- package/react/useQuery.d.ts +4 -2
- package/react/useQuery.js +36 -32
package/package.json
CHANGED
package/react/useDocument.d.ts
CHANGED
|
@@ -13,7 +13,8 @@ export declare class DocumentState<T extends Data> extends State<OptionalEntity<
|
|
|
13
13
|
get exists(): boolean;
|
|
14
14
|
constructor(ref: DocumentReference<T>);
|
|
15
15
|
/** Refresh this state from the source provider. */
|
|
16
|
-
readonly refresh: () =>
|
|
16
|
+
readonly refresh: () => void;
|
|
17
|
+
_refresh(): Promise<void>;
|
|
17
18
|
/** Refresh this state if data in the cache is older than `maxAge` (in milliseconds). */
|
|
18
19
|
refreshStale(maxAge: number): void;
|
|
19
20
|
/** Subscribe this state to the source provider. */
|
package/react/useDocument.js
CHANGED
|
@@ -18,28 +18,17 @@ export class DocumentState extends State {
|
|
|
18
18
|
super(table && isCached ? table.getDocument(ref.id) : NOVALUE);
|
|
19
19
|
this.busy = new BooleanState();
|
|
20
20
|
/** Refresh this state from the source provider. */
|
|
21
|
-
this.refresh =
|
|
21
|
+
this.refresh = () => {
|
|
22
22
|
if (this.closed)
|
|
23
23
|
throw new ConditionError("State is closed");
|
|
24
|
-
if (!this.busy.value)
|
|
25
|
-
this.
|
|
26
|
-
try {
|
|
27
|
-
const result = await this.ref.value;
|
|
28
|
-
this.next(result);
|
|
29
|
-
}
|
|
30
|
-
catch (thrown) {
|
|
31
|
-
this.error(thrown);
|
|
32
|
-
}
|
|
33
|
-
finally {
|
|
34
|
-
this.busy.next(false);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
24
|
+
if (!this.busy.value)
|
|
25
|
+
void this._refresh();
|
|
37
26
|
};
|
|
38
27
|
this._time = time;
|
|
39
28
|
this.ref = ref;
|
|
40
29
|
// Queue a request to refresh the value if it doesn't exist.
|
|
41
30
|
if (this.loading)
|
|
42
|
-
|
|
31
|
+
this.refresh();
|
|
43
32
|
}
|
|
44
33
|
/** Get the data of the document (throws `RequiredError` if document doesn't exist). */
|
|
45
34
|
get data() {
|
|
@@ -49,10 +38,23 @@ export class DocumentState extends State {
|
|
|
49
38
|
get exists() {
|
|
50
39
|
return !!this.value;
|
|
51
40
|
}
|
|
41
|
+
async _refresh() {
|
|
42
|
+
this.busy.next(true);
|
|
43
|
+
try {
|
|
44
|
+
const result = await this.ref.value;
|
|
45
|
+
this.next(result);
|
|
46
|
+
}
|
|
47
|
+
catch (thrown) {
|
|
48
|
+
this.error(thrown);
|
|
49
|
+
}
|
|
50
|
+
finally {
|
|
51
|
+
this.busy.next(false);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
52
54
|
/** Refresh this state if data in the cache is older than `maxAge` (in milliseconds). */
|
|
53
55
|
refreshStale(maxAge) {
|
|
54
56
|
if (this.age > maxAge)
|
|
55
|
-
|
|
57
|
+
this.refresh();
|
|
56
58
|
}
|
|
57
59
|
/** Subscribe this state to the source provider. */
|
|
58
60
|
connectSource() {
|
package/react/useQuery.d.ts
CHANGED
|
@@ -25,7 +25,8 @@ export declare class QueryState<T extends Data> extends State<Entities<T>> {
|
|
|
25
25
|
get count(): number;
|
|
26
26
|
constructor(ref: QueryReference<T>);
|
|
27
27
|
/** Refresh this state from the source provider. */
|
|
28
|
-
readonly refresh: () =>
|
|
28
|
+
readonly refresh: () => void;
|
|
29
|
+
_refresh(): Promise<void>;
|
|
29
30
|
/** Refresh this state if data in the cache is older than `maxAge` (in milliseconds). */
|
|
30
31
|
refreshStale(maxAge: number): void;
|
|
31
32
|
/** Subscribe this state to the source provider. */
|
|
@@ -38,7 +39,8 @@ export declare class QueryState<T extends Data> extends State<Entities<T>> {
|
|
|
38
39
|
* Load more items after the last once.
|
|
39
40
|
* - Promise that needs to be handled.
|
|
40
41
|
*/
|
|
41
|
-
readonly loadMore: () =>
|
|
42
|
+
readonly loadMore: () => void;
|
|
43
|
+
_loadMore(): Promise<void>;
|
|
42
44
|
}
|
|
43
45
|
/**
|
|
44
46
|
* Use a query in a React component.
|
package/react/useQuery.js
CHANGED
|
@@ -19,52 +19,28 @@ export class QueryState extends State {
|
|
|
19
19
|
this.busy = new BooleanState();
|
|
20
20
|
this._hasMore = false;
|
|
21
21
|
/** Refresh this state from the source provider. */
|
|
22
|
-
this.refresh =
|
|
22
|
+
this.refresh = () => {
|
|
23
23
|
if (this.closed)
|
|
24
24
|
throw new ConditionError("State is closed");
|
|
25
|
-
if (!this.busy.value)
|
|
26
|
-
this.
|
|
27
|
-
try {
|
|
28
|
-
const result = await this.ref.value;
|
|
29
|
-
this._hasMore = result.length < this.limit;
|
|
30
|
-
this.next(result);
|
|
31
|
-
}
|
|
32
|
-
catch (thrown) {
|
|
33
|
-
this.error(thrown);
|
|
34
|
-
}
|
|
35
|
-
finally {
|
|
36
|
-
this.busy.next(false);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
25
|
+
if (!this.busy.value)
|
|
26
|
+
void this._refresh();
|
|
39
27
|
};
|
|
40
28
|
/**
|
|
41
29
|
* Load more items after the last once.
|
|
42
30
|
* - Promise that needs to be handled.
|
|
43
31
|
*/
|
|
44
|
-
this.loadMore =
|
|
32
|
+
this.loadMore = () => {
|
|
45
33
|
if (this.closed)
|
|
46
34
|
throw new ConditionError("State is closed");
|
|
47
|
-
if (!this.busy.value)
|
|
48
|
-
this.
|
|
49
|
-
try {
|
|
50
|
-
const items = await this.ref.after(this.lastData).value;
|
|
51
|
-
this.next([...this.value, ...items]);
|
|
52
|
-
this._hasMore = items.length < this.limit;
|
|
53
|
-
}
|
|
54
|
-
catch (thrown) {
|
|
55
|
-
this.error(thrown);
|
|
56
|
-
}
|
|
57
|
-
finally {
|
|
58
|
-
this.busy.next(false);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
35
|
+
if (!this.busy.value)
|
|
36
|
+
void this._loadMore();
|
|
61
37
|
};
|
|
62
38
|
this._time = time;
|
|
63
39
|
this.ref = ref;
|
|
64
40
|
this.limit = (_b = ref.limit) !== null && _b !== void 0 ? _b : Infinity;
|
|
65
41
|
// Queue a request to refresh the value if it doesn't exist.
|
|
66
42
|
if (this.loading)
|
|
67
|
-
|
|
43
|
+
this.refresh();
|
|
68
44
|
}
|
|
69
45
|
/** Can more items be loaded after the current result. */
|
|
70
46
|
get hasMore() {
|
|
@@ -94,10 +70,24 @@ export class QueryState extends State {
|
|
|
94
70
|
get count() {
|
|
95
71
|
return this.value.length;
|
|
96
72
|
}
|
|
73
|
+
async _refresh() {
|
|
74
|
+
this.busy.next(true);
|
|
75
|
+
try {
|
|
76
|
+
const result = await this.ref.value;
|
|
77
|
+
this._hasMore = result.length < this.limit;
|
|
78
|
+
this.next(result);
|
|
79
|
+
}
|
|
80
|
+
catch (thrown) {
|
|
81
|
+
this.error(thrown);
|
|
82
|
+
}
|
|
83
|
+
finally {
|
|
84
|
+
this.busy.next(false);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
97
87
|
/** Refresh this state if data in the cache is older than `maxAge` (in milliseconds). */
|
|
98
88
|
refreshStale(maxAge) {
|
|
99
89
|
if (this.age > maxAge)
|
|
100
|
-
|
|
90
|
+
this.refresh();
|
|
101
91
|
}
|
|
102
92
|
/** Subscribe this state to the source provider. */
|
|
103
93
|
connectSource() {
|
|
@@ -118,6 +108,20 @@ export class QueryState extends State {
|
|
|
118
108
|
// Disconnect all sources.
|
|
119
109
|
this.disconnect();
|
|
120
110
|
}
|
|
111
|
+
async _loadMore() {
|
|
112
|
+
this.busy.next(true);
|
|
113
|
+
try {
|
|
114
|
+
const items = await this.ref.after(this.lastData).value;
|
|
115
|
+
this.next([...this.value, ...items]);
|
|
116
|
+
this._hasMore = items.length < this.limit;
|
|
117
|
+
}
|
|
118
|
+
catch (thrown) {
|
|
119
|
+
this.error(thrown);
|
|
120
|
+
}
|
|
121
|
+
finally {
|
|
122
|
+
this.busy.next(false);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
121
125
|
}
|
|
122
126
|
/** Reuse the previous `QueryState` or create a new one. */
|
|
123
127
|
const _reduceQueryState = (existing, ref) => existing || new QueryState(ref);
|