shelving 1.26.0 → 1.26.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/db/Pagination.d.ts +2 -10
- package/db/Pagination.js +16 -39
- package/package.json +1 -1
package/db/Pagination.d.ts
CHANGED
|
@@ -7,23 +7,15 @@ import { DataQuery } from "./Database.js";
|
|
|
7
7
|
* - If you don't pass in initial values, it will autoload the first page.
|
|
8
8
|
*/
|
|
9
9
|
export declare class Pagination<T extends Data> extends State<ResultsMap<T>> implements Iterable<Entry<T>> {
|
|
10
|
+
protected _pending: boolean;
|
|
10
11
|
readonly ref: DataQuery<T>;
|
|
11
12
|
readonly limit: number;
|
|
12
|
-
readonly startLoading: boolean;
|
|
13
|
-
readonly startDone: boolean;
|
|
14
|
-
readonly endLoading: boolean;
|
|
15
|
-
readonly endDone: boolean;
|
|
16
13
|
constructor(ref: DataQuery<T>);
|
|
17
|
-
/**
|
|
18
|
-
* Load more results before the start.
|
|
19
|
-
* - Promise that needs to be handled.
|
|
20
|
-
*/
|
|
21
|
-
loadStart: () => Promise<void>;
|
|
22
14
|
/**
|
|
23
15
|
* Load more results after the end.
|
|
24
16
|
* - Promise that needs to be handled.
|
|
25
17
|
*/
|
|
26
|
-
|
|
18
|
+
more: () => Promise<void>;
|
|
27
19
|
/**
|
|
28
20
|
* Merge more results into this pagination.
|
|
29
21
|
* @return The change in the number of results.
|
package/db/Pagination.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getLastItem, assertLength, assertNumber, yieldMerged, toMap, LOADING } from "../util/index.js";
|
|
2
2
|
import { State } from "../stream/index.js";
|
|
3
3
|
import { ConditionError } from "../index.js";
|
|
4
4
|
/**
|
|
@@ -9,56 +9,33 @@ import { ConditionError } from "../index.js";
|
|
|
9
9
|
export class Pagination extends State {
|
|
10
10
|
constructor(ref) {
|
|
11
11
|
super();
|
|
12
|
-
this.
|
|
13
|
-
this.startDone = false;
|
|
14
|
-
this.endLoading = false;
|
|
15
|
-
this.endDone = false;
|
|
16
|
-
/**
|
|
17
|
-
* Load more results before the start.
|
|
18
|
-
* - Promise that needs to be handled.
|
|
19
|
-
*/
|
|
20
|
-
this.loadStart = async () => {
|
|
21
|
-
if (this.closed)
|
|
22
|
-
throw new ConditionError();
|
|
23
|
-
if (!this.startLoading) {
|
|
24
|
-
this.startLoading = true;
|
|
25
|
-
if (!this.loading) {
|
|
26
|
-
const firstItem = getFirstItem(this.value);
|
|
27
|
-
if (firstItem) {
|
|
28
|
-
const next = await this.ref.after(firstItem[0], firstItem[1]).resultsMap;
|
|
29
|
-
this.startDone = next.size < this.limit;
|
|
30
|
-
this.startLoading = false;
|
|
31
|
-
return this.merge(next);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
const next = await this.ref.resultsMap;
|
|
35
|
-
this.startDone = next.size < this.limit;
|
|
36
|
-
this.startLoading = false;
|
|
37
|
-
return this.next(next);
|
|
38
|
-
}
|
|
39
|
-
};
|
|
12
|
+
this._pending = false; // Prevents double-loading.
|
|
40
13
|
/**
|
|
41
14
|
* Load more results after the end.
|
|
42
15
|
* - Promise that needs to be handled.
|
|
43
16
|
*/
|
|
44
|
-
this.
|
|
17
|
+
this.more = async () => {
|
|
45
18
|
if (this.closed)
|
|
46
|
-
throw new ConditionError();
|
|
47
|
-
if (!this.
|
|
48
|
-
this.
|
|
19
|
+
throw new ConditionError("Pagination is closed");
|
|
20
|
+
if (!this._pending) {
|
|
21
|
+
this._pending = true;
|
|
49
22
|
if (!this.loading) {
|
|
50
23
|
const lastItem = getLastItem(this.value);
|
|
51
24
|
if (lastItem) {
|
|
52
25
|
const next = await this.ref.after(lastItem[0], lastItem[1]).resultsMap;
|
|
53
|
-
this.
|
|
54
|
-
|
|
55
|
-
|
|
26
|
+
this.merge(next);
|
|
27
|
+
if (next.size < this.limit)
|
|
28
|
+
this.complete();
|
|
29
|
+
this._pending = false;
|
|
30
|
+
return;
|
|
56
31
|
}
|
|
57
32
|
}
|
|
33
|
+
this._value === LOADING;
|
|
58
34
|
const next = await this.ref.resultsMap;
|
|
59
|
-
this.
|
|
60
|
-
|
|
61
|
-
|
|
35
|
+
this.next(next);
|
|
36
|
+
if (next.size < this.limit)
|
|
37
|
+
this.complete();
|
|
38
|
+
this._pending = false;
|
|
62
39
|
}
|
|
63
40
|
};
|
|
64
41
|
this.ref = ref;
|