@arrai-innovations/reactive-helpers 20.0.1 → 20.1.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/config/listCrud.js +5 -4
- package/package.json +1 -1
- package/types/config/listCrud.d.ts +8 -4
- package/types/config/listCrud.d.ts.map +1 -1
- package/types/use/list.d.ts +2 -2
- package/types/use/list.d.ts.map +1 -1
- package/types/use/listKeys.d.ts.map +1 -1
- package/types/use/paginatedListInstance.d.ts +30 -21
- package/types/use/paginatedListInstance.d.ts.map +1 -1
- package/use/list.js +5 -2
- package/use/listKeys.js +1 -0
- package/use/paginatedListInstance.js +74 -23
package/config/listCrud.js
CHANGED
|
@@ -10,15 +10,16 @@ import { readonly } from "vue";
|
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* @typedef {object} PaginateInfo
|
|
13
|
-
* @property {number} totalRecords - The total records.
|
|
14
|
-
* @property {number} totalPages - The total pages.
|
|
15
|
-
* @property {number} perPage - The per page.
|
|
13
|
+
* @property {number} [totalRecords] - The total records.
|
|
14
|
+
* @property {number} [totalPages] - The total pages.
|
|
15
|
+
* @property {number} [perPage] - The per page.
|
|
16
|
+
* @property {number} [page] - The page you are giving us results for.
|
|
16
17
|
*/
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* @typedef {(
|
|
20
21
|
* newObjects:import('../use/listInstance.js').ListObject,
|
|
21
|
-
* paginationInfo
|
|
22
|
+
* paginationInfo?: PaginateInfo,
|
|
22
23
|
* )=>void} PageCallback
|
|
23
24
|
*/
|
|
24
25
|
|
package/package.json
CHANGED
|
@@ -13,17 +13,21 @@ export type PaginateInfo = {
|
|
|
13
13
|
/**
|
|
14
14
|
* - The total records.
|
|
15
15
|
*/
|
|
16
|
-
totalRecords
|
|
16
|
+
totalRecords?: number;
|
|
17
17
|
/**
|
|
18
18
|
* - The total pages.
|
|
19
19
|
*/
|
|
20
|
-
totalPages
|
|
20
|
+
totalPages?: number;
|
|
21
21
|
/**
|
|
22
22
|
* - The per page.
|
|
23
23
|
*/
|
|
24
|
-
perPage
|
|
24
|
+
perPage?: number;
|
|
25
|
+
/**
|
|
26
|
+
* - The page you are giving us results for.
|
|
27
|
+
*/
|
|
28
|
+
page?: number;
|
|
25
29
|
};
|
|
26
|
-
export type PageCallback = (newObjects: import("../use/listInstance.js").ListObject, paginationInfo
|
|
30
|
+
export type PageCallback = (newObjects: import("../use/listInstance.js").ListObject, paginationInfo?: PaginateInfo) => void;
|
|
27
31
|
export type ListArgs = {
|
|
28
32
|
/**
|
|
29
33
|
* - The arguments to be passed to the crud handlers.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listCrud.d.ts","sourceRoot":"","sources":["../../config/listCrud.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"listCrud.d.ts","sourceRoot":"","sources":["../../config/listCrud.js"],"names":[],"mappings":"AAmHA;;;;GAIG;AACH,8BAFU,QAAQ,CAAC,gBAAgB,CAAC,CAEkB;AAS/C,+CAJI,gBAAgB,GAAG,OAAO,CAAC,UAAU,CAAC,GAEpC,IAAI,CAUhB;AAWM,oCANI,OAAO,KAAK,EAAE,gBAAgB,CAAC,gBAAgB,GAAG,UAAU,CAAC,WAErE;IAAmE,KAAK,GAAhE,OAAO,KAAK,EAAE,gBAAgB,CAAC,gBAAgB,CAAC;IACrB,QAAQ,GAAnC,gBAAgB;CACxB,QAIF;;;;;mBA1Ia,MAAM;;;;iBACN,MAAM;;;;cACN,MAAM;;;;WACN,MAAM;;2BAIP,CACN,UAAU,EAAC,OAAO,wBAAwB,EAAE,UAAU,EACtD,cAAc,CAAC,EAAE,YAAY,KAC9B,IAAI;;;;;YAKI,MAAM;;;;WACN,MAAM;;;;YACN,MAAM;;;;kBACN,YAAY;;;;;iBACZ,QAAQ,CAAC,OAAO,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;;;;;;YAMpC,MAAM;;;;SACN,MAAM,EAAE;;;;WACR,MAAM;;;;;iBACN,QAAQ,CAAC,OAAO,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;;wCAKrC,CACN,0BAA0B,EAAC,OAAO,wBAAwB,EAAE,UAAU,GAAC,MAAM,EAC7E,MAAM,EAAE,QAAQ,GAAC,QAAQ,GAAC,QAAQ,KACnC,IAAI;;;;;YAKI,MAAM;;;;WACN,MAAM;;;;YACN,MAAM;;;;+BACN,yBAAyB;;;;;iBACzB,QAAQ,CAAC,OAAO,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;;;;;;YAMpC,MAAM;;;;SACN,MAAM,EAAE;;;;WACR,MAAM;;;;YACN,MAAM;;;;;iBACN,QAAQ,CAAC,OAAO,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;;gCAMvC,QAAQ,KACN,OAAO,gCAAgC,EAAE,uBAAuB,CAAC,IAAI,CAAC;sCAKxE,cAAc,KACZ,OAAO,gCAAgC,EAAE,uBAAuB,CAAC,IAAI,CAAC;yCAKxE,iBAAiB,KACf,OAAO,gCAAgC,EAAE,kBAAkB,CAAC,IAAI,CAAC;yCAKnE,iBAAiB,KACf,OAAO,gCAAgC,EAAE,uBAAuB,CAAC,MAAM,GAAC,MAAM,GAAC,IAAI,CAAC;;;;;WAKnF,UAAU;;;;iBACV,gBAAgB;;;;oBAChB,mBAAmB;;;;gBACnB,mBAAmB;;;;;;UAKnB,MAAM;;;;;;aAKN,MAAM"}
|
package/types/use/list.d.ts
CHANGED
|
@@ -124,7 +124,7 @@ export type ListOptions = {
|
|
|
124
124
|
* Represents the combined state definitions for all list-related components.
|
|
125
125
|
* This interface aggregates the raw state from multiple list management functionalities.
|
|
126
126
|
*/
|
|
127
|
-
export type ListRawState = (import("./listInstance.js").ListInstanceRawState & import("./listSubscription.js").ListSubscriptionRawState & import("./listRelated.js").ListRelatedRawState & import("./listCalculated.js").ListCalculatedRawState & import("./listFilter.js").ListFilterRawState & import("./listSearch.js").ListSearchRawState & import("./listSort.js").ListSortRawState);
|
|
127
|
+
export type ListRawState = ((import("./listInstance.js").ListInstanceRawState | import("./paginatedListInstance.js").PagedListInstanceRawState) & import("./listSubscription.js").ListSubscriptionRawState & import("./listRelated.js").ListRelatedRawState & import("./listCalculated.js").ListCalculatedRawState & import("./listFilter.js").ListFilterRawState & import("./listSearch.js").ListSearchRawState & import("./listSort.js").ListSortRawState);
|
|
128
128
|
/**
|
|
129
129
|
* Represents the reactive state derived from aggregating states of various list-related components.
|
|
130
130
|
* This state is typically used within Vue components for reactivity and access to updated list properties.
|
|
@@ -134,7 +134,7 @@ export type ListState = import("vue").UnwrapNestedRefs<ListRawState>;
|
|
|
134
134
|
* Holds references to instances of all list-related composables, facilitating direct access and management.
|
|
135
135
|
*/
|
|
136
136
|
export type ListManaged = {
|
|
137
|
-
listInstance: import("./listInstance.js").ListInstance;
|
|
137
|
+
listInstance: import("./listInstance.js").ListInstance | import("./paginatedListInstance.js").PagedListInstance;
|
|
138
138
|
listSubscription: import("./listSubscription.js").ListSubscription;
|
|
139
139
|
listRelated: import("./listRelated.js").ListRelated;
|
|
140
140
|
listCalculated: import("./listCalculated.js").ListCalculated;
|
package/types/use/list.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../use/list.js"],"names":[],"mappings":"AAmBA;;;;;;;GAOG;AAEH;;GAEG;AACH;IACI;;;;;OAKG;IACH,qBAHW,MAAM,QACN,MAAM,EAMhB;IADG,aAAgB;CAEvB;
|
|
1
|
+
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../use/list.js"],"names":[],"mappings":"AAmBA;;;;;;;GAOG;AAEH;;GAEG;AACH;IACI;;;;;OAKG;IACH,qBAHW,MAAM,QACN,MAAM,EAMhB;IADG,aAAgB;CAEvB;AAmHM,sCAPI;IACV,CAAO,GAAG,EAAE,MAAM,GAAG,WAAW,CAAA;CAC7B,GACS;IACZ,CAAM,GAAG,EAAE,MAAM,GAAG,WAAW,CAAA;CAC5B,CASH;AAcM,6JAJI,WAAW,GACT,WAAW,CAwHvB;;;;;;;;YAvPa,MAAM;;;;WACN,MAAM;;;;YACN,MAAM;;;;kBACN,OAAO;;;;uBACP,OAAO;;;;yBACP,OAAO,kBAAkB,EAAE,gBAAgB;;;;4BAC3C,OAAO,qBAAqB,EAAE,mBAAmB;;;;mBACjD,OAAO,iBAAiB,EAAE,uBAAuB;;;;oBACjD,OAAO,iBAAiB,EAAE,wBAAwB;;;;qBAClD,OAAO,iBAAiB,EAAE,eAAe;;;;qBACzC,MAAM;;;;2BACN,MAAM;;;;yBACN,MAAM;;;;kBACN,OAAO,eAAe,EAAE,WAAW,EAAE;;;;;;WAKrC,YAAY;;;;cACZ,OAAO,uBAAuB,EAAE,gBAAgB;;;;WAChD,OAAO;;;;kBACP,OAAO;;;;oCACP,OAAO;;;;oBACP,MAAM;;;;sBACN,MAAM;;;;4BACN,OAAO;;;;;;2BAOR,CACZ,CACA,OAAiB,mBAAmB,EAAE,oBAAoB,GAC1D,OAAiB,4BAA4B,EAAE,yBAAyB,CACjE,GACP,OAAa,uBAAuB,EAAE,wBAAwB,GAC9D,OAAa,kBAAkB,EAAE,mBAAmB,GACpD,OAAa,qBAAqB,EAAE,sBAAsB,GAC1D,OAAa,iBAAiB,EAAE,kBAAkB,GAClD,OAAa,iBAAiB,EAAE,kBAAkB,GAClD,OAAa,eAAe,EAAE,gBAAgB,CAC3C;;;;;wBAOS,OAAO,KAAK,EAAE,gBAAgB,CAAC,YAAY,CAAC;;;;0BAM5C;IACN,YAAY,EAAE,OAAO,mBAAmB,EAAE,YAAY,GAAG,OAAO,4BAA4B,EAAE,iBAAiB,CAAC;IAChH,gBAAgB,EAAE,OAAO,uBAAuB,EAAE,gBAAgB,CAAC;IACnE,WAAW,EAAE,OAAO,kBAAkB,EAAE,WAAW,CAAC;IACpD,cAAc,EAAE,OAAO,qBAAqB,EAAE,cAAc,CAAC;IAC7D,UAAU,EAAE,OAAO,iBAAiB,EAAE,UAAU,CAAC;IACjD,UAAU,EAAE,OAAO,iBAAiB,EAAE,UAAU,CAAC;IACjD,QAAQ,EAAE,OAAO,eAAe,EAAE,QAAQ,CAAA;CAC7C;;;;4BAMS,CACZ,OAAa,mBAAmB,EAAE,qBAAqB,GAC/C,OAAO,uBAAuB,EAAE,yBAAyB,CAC9D;;;;;;;;;aAcU,WAAW;;;;WACX,SAAS;;;;iBACT,OAAO,KAAK,EAAE,WAAW;;;;;;0BAO1B,aAAa,GAAG,qBAAqB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listKeys.d.ts","sourceRoot":"","sources":["../../use/listKeys.js"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"listKeys.d.ts","sourceRoot":"","sources":["../../use/listKeys.js"],"names":[],"mappings":"AAAA,6CAiBE;AACF,6CAYE;AAEF,iDAOE;AACF,iDAAoF;AAEpF,4CAQE;AACF,yCAAuC;AAEvC,+CAME;AACF,4CAA0C;AAE1C,2CAWE;AACF,wCAAsC;AAEtC,2CAcE;AACF,wCAAsC;AACtC,yCAWE;AACF,sCAAoC"}
|
|
@@ -1,21 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module use/paginatedListInstance.js
|
|
3
|
-
*
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @typedef {object} PagedListListanceOptions
|
|
7
|
-
* @property {boolean} keepOldPages - Whether to keep old pages.
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* @typedef {object} PagedListInstanceState
|
|
11
|
-
* @property {number} totalRecords - The total records.
|
|
12
|
-
* @property {number} totalPages - The total pages.
|
|
13
|
-
* @property {number} perPage - The per page.
|
|
14
|
-
*/
|
|
15
|
-
/**
|
|
16
|
-
* @typedef {object} PagedListInstance
|
|
17
|
-
* @property {import('./listInstance.js').ListInstanceState & PagedListInstanceState} state - The state.
|
|
18
|
-
*/
|
|
19
1
|
/**
|
|
20
2
|
*
|
|
21
3
|
* @param {PagedListListanceOptions & import('./listInstance.js').ListInstanceOptions} options - The options.
|
|
@@ -28,7 +10,7 @@ export type PagedListListanceOptions = {
|
|
|
28
10
|
*/
|
|
29
11
|
keepOldPages: boolean;
|
|
30
12
|
};
|
|
31
|
-
export type
|
|
13
|
+
export type PaginatedRawState = {
|
|
32
14
|
/**
|
|
33
15
|
* - The total records.
|
|
34
16
|
*/
|
|
@@ -41,11 +23,38 @@ export type PagedListInstanceState = {
|
|
|
41
23
|
* - The per page.
|
|
42
24
|
*/
|
|
43
25
|
perPage: number;
|
|
26
|
+
/**
|
|
27
|
+
* - The page to ids map.
|
|
28
|
+
*/
|
|
29
|
+
pageToIds: Map<number, string[]>;
|
|
30
|
+
};
|
|
31
|
+
export type PaginatedState = import("vue").UnwrapNestedRefs<PaginatedRawState>;
|
|
32
|
+
export type PagedListInstanceStateExtension = {
|
|
33
|
+
/**
|
|
34
|
+
* - The total records.
|
|
35
|
+
*/
|
|
36
|
+
totalRecords: import("vue").Ref<number>;
|
|
37
|
+
/**
|
|
38
|
+
* - The total pages.
|
|
39
|
+
*/
|
|
40
|
+
totalPages: import("vue").Ref<number>;
|
|
41
|
+
/**
|
|
42
|
+
* - The per page.
|
|
43
|
+
*/
|
|
44
|
+
perPage: import("vue").Ref<number>;
|
|
45
|
+
/**
|
|
46
|
+
* - The page to ids map.
|
|
47
|
+
*/
|
|
48
|
+
pageToIds: import("vue").Ref<Map<number, string[]>>;
|
|
44
49
|
};
|
|
45
|
-
export type
|
|
50
|
+
export type PagedListInstanceRawState = import("./listInstance.js").ListInstanceRawState & PagedListInstanceStateExtension;
|
|
51
|
+
export type PagedListInstanceState = typeof reactive;
|
|
52
|
+
export type PagedListRawInstance = {
|
|
46
53
|
/**
|
|
47
54
|
* - The state.
|
|
48
55
|
*/
|
|
49
|
-
state:
|
|
56
|
+
state: PagedListInstanceState;
|
|
50
57
|
};
|
|
58
|
+
export type PagedListInstance = import("./listInstance.js").ListInstance & PagedListRawInstance;
|
|
59
|
+
import { reactive } from "vue";
|
|
51
60
|
//# sourceMappingURL=paginatedListInstance.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paginatedListInstance.d.ts","sourceRoot":"","sources":["../../use/paginatedListInstance.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"paginatedListInstance.d.ts","sourceRoot":"","sources":["../../use/paginatedListInstance.js"],"names":[],"mappings":"AA4DA;;;;GAIG;AACH,+EAHW,wBAAwB,GAAG,OAAO,mBAAmB,EAAE,mBAAmB,GACxE,iBAAiB,CA8D7B;;;;;kBAnHa,OAAO;;;;;;kBAKP,MAAM;;;;gBACN,MAAM;;;;aACN,MAAM;;;;eACN,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;;6BAItB,OAAO,KAAK,EAAE,gBAAgB,CAAC,iBAAiB,CAAC;;;;;kBAKhD,OAAO,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC;;;;gBACzB,OAAO,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC;;;;aACzB,OAAO,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC;;;;eACzB,OAAO,KAAK,EAAE,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;;wCAIzC,OAAO,mBAAmB,EAAE,oBAAoB,GAAG,+BAA+B;;;;;;WASjF,sBAAsB;;gCAIvB,OAAO,mBAAmB,EAAE,YAAY,GAAG,oBAAoB;yBA9C3C,KAAK"}
|
package/use/list.js
CHANGED
|
@@ -80,7 +80,10 @@ export class ListError extends Error {
|
|
|
80
80
|
* This interface aggregates the raw state from multiple list management functionalities.
|
|
81
81
|
*
|
|
82
82
|
* @typedef {(
|
|
83
|
-
*
|
|
83
|
+
* (
|
|
84
|
+
* import('./listInstance.js').ListInstanceRawState |
|
|
85
|
+
* import('./paginatedListInstance.js').PagedListInstanceRawState
|
|
86
|
+
* ) &
|
|
84
87
|
* import('./listSubscription.js').ListSubscriptionRawState &
|
|
85
88
|
* import('./listRelated.js').ListRelatedRawState &
|
|
86
89
|
* import('./listCalculated.js').ListCalculatedRawState &
|
|
@@ -101,7 +104,7 @@ export class ListError extends Error {
|
|
|
101
104
|
* Holds references to instances of all list-related composables, facilitating direct access and management.
|
|
102
105
|
*
|
|
103
106
|
* @typedef {{
|
|
104
|
-
* listInstance: import('./listInstance.js').ListInstance,
|
|
107
|
+
* listInstance: import('./listInstance.js').ListInstance | import('./paginatedListInstance.js').PagedListInstance,
|
|
105
108
|
* listSubscription: import('./listSubscription.js').ListSubscription,
|
|
106
109
|
* listRelated: import('./listRelated.js').ListRelated,
|
|
107
110
|
* listCalculated: import('./listCalculated.js').ListCalculated,
|
package/use/listKeys.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useListInstance } from "./listInstance.js";
|
|
2
|
+
import { reactive, toRefs } from "vue";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* @module use/paginatedListInstance.js
|
|
@@ -11,65 +12,115 @@ import { useListInstance } from "./listInstance.js";
|
|
|
11
12
|
*/
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
|
-
* @typedef {object}
|
|
15
|
+
* @typedef {object} PaginatedRawState
|
|
15
16
|
* @property {number} totalRecords - The total records.
|
|
16
17
|
* @property {number} totalPages - The total pages.
|
|
17
18
|
* @property {number} perPage - The per page.
|
|
19
|
+
* @property {Map<number, string[]>} pageToIds - The page to ids map.
|
|
18
20
|
*/
|
|
19
21
|
|
|
20
22
|
/**
|
|
21
|
-
* @typedef {
|
|
22
|
-
* @property {import('./listInstance.js').ListInstanceState & PagedListInstanceState} state - The state.
|
|
23
|
+
* @typedef {import('vue').UnwrapNestedRefs<PaginatedRawState>} PaginatedState
|
|
23
24
|
*/
|
|
24
25
|
|
|
26
|
+
/**
|
|
27
|
+
* @typedef {object} PagedListInstanceStateExtension
|
|
28
|
+
* @property {import('vue').Ref<number>} totalRecords - The total records.
|
|
29
|
+
* @property {import('vue').Ref<number>} totalPages - The total pages.
|
|
30
|
+
* @property {import('vue').Ref<number>} perPage - The per page.
|
|
31
|
+
* @property {import('vue').Ref<Map<number, string[]>>} pageToIds - The page to ids map.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @typedef {import('./listInstance.js').ListInstanceRawState & PagedListInstanceStateExtension} PagedListInstanceRawState
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @typedef {import('vue').reactive<PagedListInstanceRawState>} PagedListInstanceState
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @typedef {object} PagedListRawInstance
|
|
44
|
+
* @property {PagedListInstanceState} state - The state.
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @typedef {import('./listInstance.js').ListInstance & PagedListRawInstance} PagedListInstance
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @param {import('./listInstance.js').ListInstance} listInstance - The list instance.
|
|
53
|
+
* @param {PaginatedState} paginatedState - The paginated state.
|
|
54
|
+
* @returns {PagedListInstance} - The paged list instance.
|
|
55
|
+
*/
|
|
56
|
+
function makePagedListInstance(listInstance, paginatedState) {
|
|
57
|
+
Object.assign(listInstance.state, toRefs(paginatedState));
|
|
58
|
+
return /** @type {PagedListInstance} */ (listInstance);
|
|
59
|
+
}
|
|
60
|
+
|
|
25
61
|
/**
|
|
26
62
|
*
|
|
27
63
|
* @param {PagedListListanceOptions & import('./listInstance.js').ListInstanceOptions} options - The options.
|
|
28
64
|
* @returns {PagedListInstance} - The paged list instance.
|
|
29
65
|
*/
|
|
30
66
|
export function usePagedListInstance({ keepOldPages, ...useListInstanceArgs }) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
67
|
+
/** @type {PaginatedState} */
|
|
68
|
+
const paginatedState = reactive({
|
|
69
|
+
totalRecords: 0,
|
|
70
|
+
totalPages: 0,
|
|
71
|
+
perPage: 0,
|
|
72
|
+
pageToIds: new Map(),
|
|
73
|
+
});
|
|
34
74
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
75
|
+
const paginatedListInstance = makePagedListInstance(
|
|
76
|
+
useListInstance({ keepOldPages, ...useListInstanceArgs }),
|
|
77
|
+
paginatedState
|
|
78
|
+
);
|
|
38
79
|
|
|
39
|
-
const superClearList =
|
|
40
|
-
|
|
80
|
+
const superClearList = paginatedListInstance.clearList;
|
|
81
|
+
paginatedListInstance.clearList = () => {
|
|
41
82
|
superClearList();
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
83
|
+
paginatedState.totalRecords = 0;
|
|
84
|
+
paginatedState.totalPages = 0;
|
|
85
|
+
paginatedState.perPage = 0;
|
|
86
|
+
paginatedState.pageToIds.clear();
|
|
45
87
|
};
|
|
46
88
|
if (keepOldPages === undefined) {
|
|
47
89
|
throw new Error("keepOldPages is required");
|
|
48
90
|
}
|
|
49
91
|
|
|
50
|
-
|
|
92
|
+
paginatedListInstance.pageCallback = (
|
|
93
|
+
/** @type {import('./listInstance.js').ListObject[]} */ newObjects,
|
|
94
|
+
/** @type {import('../config/listCrud.js').PaginateInfo} */ { page, totalRecords, totalPages, perPage }
|
|
95
|
+
) => {
|
|
51
96
|
// with keepOldPages, you are responsible for clearing the list as needed
|
|
52
97
|
if (!keepOldPages) {
|
|
53
98
|
// display one page at a time, clear the list
|
|
54
|
-
|
|
99
|
+
paginatedListInstance.clearList();
|
|
55
100
|
}
|
|
56
101
|
newObjects.forEach((newObject) => {
|
|
57
|
-
if (newObject[
|
|
58
|
-
|
|
102
|
+
if (newObject[paginatedListInstance.state.pkKey] in paginatedListInstance.state.objects) {
|
|
103
|
+
paginatedListInstance.updateListObject(newObject);
|
|
59
104
|
} else {
|
|
60
|
-
|
|
105
|
+
paginatedListInstance.addListObject(newObject);
|
|
61
106
|
}
|
|
62
107
|
});
|
|
108
|
+
if (keepOldPages && page !== undefined) {
|
|
109
|
+
const pageIds = newObjects.map((obj) => obj[paginatedListInstance.state.pkKey] + "");
|
|
110
|
+
// webstorm being crazy
|
|
111
|
+
// noinspection JSUnresolvedReference
|
|
112
|
+
paginatedState.pageToIds.set(page, pageIds);
|
|
113
|
+
}
|
|
63
114
|
if (totalRecords !== undefined) {
|
|
64
|
-
|
|
115
|
+
paginatedState.totalRecords = totalRecords;
|
|
65
116
|
}
|
|
66
117
|
if (totalPages !== undefined) {
|
|
67
|
-
|
|
118
|
+
paginatedState.totalPages = totalPages;
|
|
68
119
|
}
|
|
69
120
|
if (perPage !== undefined) {
|
|
70
|
-
|
|
121
|
+
paginatedState.perPage = perPage;
|
|
71
122
|
}
|
|
72
123
|
};
|
|
73
124
|
|
|
74
|
-
return
|
|
125
|
+
return paginatedListInstance;
|
|
75
126
|
}
|