@arrai-innovations/reactive-helpers 21.0.0 → 21.0.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/README.md +1 -0
- package/package.json +1 -1
- package/types/use/listInstance.d.ts +32 -5
- package/use/listInstance.js +24 -7
package/README.md
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
[](https://docs.arrai-dev.com/reactive-helpers/artifacts/main/coverage_tests/)
|
|
5
5
|

|
|
6
6
|

|
|
7
|
+

|
|
7
8
|
|
|
8
9
|
Vue.js 3 composition utilities to manage reactive lists, objects and other helpers.
|
|
9
10
|
|
package/package.json
CHANGED
|
@@ -83,7 +83,15 @@
|
|
|
83
83
|
* @typedef {(newObjects: import('../use/objectInstance.js').ExistingCrudObject[]) => void} PushObjectsFn
|
|
84
84
|
*/
|
|
85
85
|
/**
|
|
86
|
-
*
|
|
86
|
+
* Options to control which reactive state is reset when clearing the list.
|
|
87
|
+
*
|
|
88
|
+
* @typedef {object} ClearListOptions
|
|
89
|
+
* @property {boolean} [keepPagination] - When true, keep the current pagination information.
|
|
90
|
+
* @property {boolean} [keepColumnTotals] - When true, keep the current column totals.
|
|
91
|
+
* @property {boolean} [keepError] - When true, keep the current error state.
|
|
92
|
+
*/
|
|
93
|
+
/**
|
|
94
|
+
* @typedef {(options?: ClearListOptions) => void} ClearListFn
|
|
87
95
|
*/
|
|
88
96
|
/**
|
|
89
97
|
* @typedef {(info: PaginateInfo) => void} SetPaginateInfoFn
|
|
@@ -99,7 +107,8 @@
|
|
|
99
107
|
* @property {(object: import('../use/objectInstance.js').ExistingCrudObject) => void} addListObject - Adds an object to the list.
|
|
100
108
|
* @property {(object: import('../use/objectInstance.js').ExistingCrudObject) => void} updateListObject - Updates an object in the list.
|
|
101
109
|
* @property {(objectId: string) => void} deleteListObject - Deletes an object from the list by pk.
|
|
102
|
-
* @property {() => void} clearList - Clears
|
|
110
|
+
* @property {(options?: ClearListOptions) => void} clearList - Clears the list objects and optionally keeps pagination, totals,
|
|
111
|
+
* or error state.
|
|
103
112
|
* @property {() => string} getFakePk - Generates a unique fake pk for use within the list.
|
|
104
113
|
* @property {() => import('../utils/cancellablePromise.js').MaybeCancellablePromise<boolean|never>} list - Initiates a fetch to retrieve objects according to the CRUD configuration, returning a promise to a boolean indicating success.
|
|
105
114
|
* @property {(args: {pks?: string[]}) => Promise<boolean>} bulkDelete - Deletes objects from the list by pk, returning a promise to a boolean indicating success.
|
|
@@ -343,7 +352,24 @@ export type ListInstanceRawState = ListInstanceRawMyState & Pick<import("./loadi
|
|
|
343
352
|
*/
|
|
344
353
|
export type ListInstanceState = import("vue").UnwrapNestedRefs<ListInstanceRawState>;
|
|
345
354
|
export type PushObjectsFn = (newObjects: import("../use/objectInstance.js").ExistingCrudObject[]) => void;
|
|
346
|
-
|
|
355
|
+
/**
|
|
356
|
+
* Options to control which reactive state is reset when clearing the list.
|
|
357
|
+
*/
|
|
358
|
+
export type ClearListOptions = {
|
|
359
|
+
/**
|
|
360
|
+
* - When true, keep the current pagination information.
|
|
361
|
+
*/
|
|
362
|
+
keepPagination?: boolean;
|
|
363
|
+
/**
|
|
364
|
+
* - When true, keep the current column totals.
|
|
365
|
+
*/
|
|
366
|
+
keepColumnTotals?: boolean;
|
|
367
|
+
/**
|
|
368
|
+
* - When true, keep the current error state.
|
|
369
|
+
*/
|
|
370
|
+
keepError?: boolean;
|
|
371
|
+
};
|
|
372
|
+
export type ClearListFn = (options?: ClearListOptions) => void;
|
|
347
373
|
export type SetPaginateInfoFn = (info: PaginateInfo) => void;
|
|
348
374
|
export type SetColumnTotalsFn = (total: ColumnTotals) => void;
|
|
349
375
|
/**
|
|
@@ -367,9 +393,10 @@ export type ListInstanceMyFunctions = {
|
|
|
367
393
|
*/
|
|
368
394
|
deleteListObject: (objectId: string) => void;
|
|
369
395
|
/**
|
|
370
|
-
* - Clears
|
|
396
|
+
* - Clears the list objects and optionally keeps pagination, totals,
|
|
397
|
+
* or error state.
|
|
371
398
|
*/
|
|
372
|
-
clearList: () => void;
|
|
399
|
+
clearList: (options?: ClearListOptions) => void;
|
|
373
400
|
/**
|
|
374
401
|
* - Generates a unique fake pk for use within the list.
|
|
375
402
|
*/
|
package/use/listInstance.js
CHANGED
|
@@ -129,7 +129,16 @@ export class ListInstanceError extends Error {
|
|
|
129
129
|
*/
|
|
130
130
|
|
|
131
131
|
/**
|
|
132
|
-
*
|
|
132
|
+
* Options to control which reactive state is reset when clearing the list.
|
|
133
|
+
*
|
|
134
|
+
* @typedef {object} ClearListOptions
|
|
135
|
+
* @property {boolean} [keepPagination] - When true, keep the current pagination information.
|
|
136
|
+
* @property {boolean} [keepColumnTotals] - When true, keep the current column totals.
|
|
137
|
+
* @property {boolean} [keepError] - When true, keep the current error state.
|
|
138
|
+
*/
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* @typedef {(options?: ClearListOptions) => void} ClearListFn
|
|
133
142
|
*/
|
|
134
143
|
|
|
135
144
|
/**
|
|
@@ -148,7 +157,8 @@ export class ListInstanceError extends Error {
|
|
|
148
157
|
* @property {(object: import('../use/objectInstance.js').ExistingCrudObject) => void} addListObject - Adds an object to the list.
|
|
149
158
|
* @property {(object: import('../use/objectInstance.js').ExistingCrudObject) => void} updateListObject - Updates an object in the list.
|
|
150
159
|
* @property {(objectId: string) => void} deleteListObject - Deletes an object from the list by pk.
|
|
151
|
-
* @property {() => void} clearList - Clears
|
|
160
|
+
* @property {(options?: ClearListOptions) => void} clearList - Clears the list objects and optionally keeps pagination, totals,
|
|
161
|
+
* or error state.
|
|
152
162
|
* @property {() => string} getFakePk - Generates a unique fake pk for use within the list.
|
|
153
163
|
* @property {() => import('../utils/cancellablePromise.js').MaybeCancellablePromise<boolean|never>} list - Initiates a fetch to retrieve objects according to the CRUD configuration, returning a promise to a boolean indicating success.
|
|
154
164
|
* @property {(args: {pks?: string[]}) => Promise<boolean>} bulkDelete - Deletes objects from the list by pk, returning a promise to a boolean indicating success.
|
|
@@ -560,12 +570,19 @@ export function useListInstance({ props, handlers = {} }) {
|
|
|
560
570
|
}
|
|
561
571
|
delete state.objects[pk];
|
|
562
572
|
},
|
|
563
|
-
clearList: () => {
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
573
|
+
clearList: (options) => {
|
|
574
|
+
const { keepPagination = false, keepColumnTotals = false, keepError = false } = options || {};
|
|
575
|
+
|
|
576
|
+
if (!keepPagination) {
|
|
577
|
+
assignReactiveObject(state.paginateInfo, {});
|
|
578
|
+
}
|
|
579
|
+
if (!keepColumnTotals) {
|
|
580
|
+
assignReactiveObject(state.columnTotals, {});
|
|
581
|
+
}
|
|
567
582
|
state.objectsMap.clear();
|
|
568
|
-
|
|
583
|
+
if (!keepError) {
|
|
584
|
+
loadingError.clearError();
|
|
585
|
+
}
|
|
569
586
|
},
|
|
570
587
|
clearError: loadingError.clearError,
|
|
571
588
|
getFakePk: () => getFakePk(state.objects, state.pkKey),
|