@arrai-innovations/reactive-helpers 13.0.2 → 13.0.4
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 +69 -3
- package/config/objectCrud.js +62 -6
- package/docs/config/listCrud.md +207 -4
- package/docs/config/objectCrud.md +234 -12
- package/docs/use/combineClasses.md +9 -1
- package/docs/use/listInstance.md +17 -2
- package/docs/use/loadingError.md +70 -2
- package/docs/use/object.md +120 -24
- package/docs/use/objectCalculated.md +120 -24
- package/docs/use/objectInstance.md +120 -24
- package/docs/use/objectRelated.md +120 -24
- package/docs/use/objectSubscription.md +60 -12
- package/index.js +1 -0
- package/package.json +1 -1
- package/tests/unit/config/listCrud.spec.js +1 -1
- package/tests/unit/use/listInstance.spec.js +49 -1
- package/use/combineClasses.js +10 -6
- package/use/listInstance.js +34 -1
- package/use/listKeys.js +1 -0
- package/use/loadingError.js +13 -6
package/use/listInstance.js
CHANGED
|
@@ -51,7 +51,12 @@ export class ListInstanceError extends Error {
|
|
|
51
51
|
* @typedef {object} ListInstanceOptions
|
|
52
52
|
* @property {import('vue').UnwrapNestedRefs<ListInstanceProps>} props - The props for the list instance.
|
|
53
53
|
* @property {object} [functions] - Default implementation are used as set by `setListCrud`.
|
|
54
|
-
* @property {
|
|
54
|
+
* @property {import('../config/listCrud.js').ListFn} [functions.list] - Provide the implementation for the list
|
|
55
|
+
* function.
|
|
56
|
+
* @property {import('../config/listCrud.js').BulkDeleteFn} [functions.bulkDelete] - Provide the implementation for the bulkDelete
|
|
57
|
+
* function.
|
|
58
|
+
* @property {import('../config/listCrud.js').SubscribeFn} [functions.subscribe] - Provide the implementation for the
|
|
59
|
+
* subscribe function.
|
|
55
60
|
* @property {boolean} [keepOldPages=false] - If true, pages will not be cleared when defaultPageCallback is called.
|
|
56
61
|
*/
|
|
57
62
|
|
|
@@ -251,6 +256,7 @@ export function useListInstance({ props, functions = {}, keepOldPages = false })
|
|
|
251
256
|
crud: {
|
|
252
257
|
args: {},
|
|
253
258
|
list: undefined,
|
|
259
|
+
bulkDelete: undefined,
|
|
254
260
|
},
|
|
255
261
|
retrieveArgs: toRef(props, "retrieveArgs"),
|
|
256
262
|
listArgs: toRef(props, "listArgs"),
|
|
@@ -289,6 +295,31 @@ export function useListInstance({ props, functions = {}, keepOldPages = false })
|
|
|
289
295
|
list: null,
|
|
290
296
|
};
|
|
291
297
|
|
|
298
|
+
async function bulkDeleteFn() {
|
|
299
|
+
if (state.loading) {
|
|
300
|
+
return Promise.reject(new ListInstanceError("already loading.", "already-loading"));
|
|
301
|
+
}
|
|
302
|
+
loadingError.setLoading();
|
|
303
|
+
loadingError.clearError();
|
|
304
|
+
return state.crud
|
|
305
|
+
.bulkDelete({
|
|
306
|
+
crudArgs: state.crud.args,
|
|
307
|
+
ids: Object.keys(state.objects).map(Number),
|
|
308
|
+
})
|
|
309
|
+
.then(() => {
|
|
310
|
+
assignReactiveObject(state.objects, {});
|
|
311
|
+
loadingError.clearError();
|
|
312
|
+
return Promise.resolve(true);
|
|
313
|
+
})
|
|
314
|
+
.catch((error) => {
|
|
315
|
+
loadingError.setError(error);
|
|
316
|
+
return Promise.resolve(false);
|
|
317
|
+
})
|
|
318
|
+
.finally(() => {
|
|
319
|
+
loadingError.clearLoading();
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
|
|
292
323
|
function list() {
|
|
293
324
|
// this function cannot be async, or the resulting promise will lose its .cancel() method
|
|
294
325
|
if (promises.list) {
|
|
@@ -313,6 +344,7 @@ export function useListInstance({ props, functions = {}, keepOldPages = false })
|
|
|
313
344
|
pageCallback: returnedObject.pageCallback,
|
|
314
345
|
isCancelled: readonly(isCancelled),
|
|
315
346
|
});
|
|
347
|
+
|
|
316
348
|
let resolveState = false;
|
|
317
349
|
if (listPromise.cancel) {
|
|
318
350
|
promises.list.cancel = async () => {
|
|
@@ -419,6 +451,7 @@ export function useListInstance({ props, functions = {}, keepOldPages = false })
|
|
|
419
451
|
const returnedObject = {
|
|
420
452
|
state,
|
|
421
453
|
list,
|
|
454
|
+
bulkDelete: bulkDeleteFn,
|
|
422
455
|
addListObject,
|
|
423
456
|
updateListObject,
|
|
424
457
|
deleteListObject,
|
package/use/listKeys.js
CHANGED
package/use/loadingError.js
CHANGED
|
@@ -5,20 +5,27 @@ import { readonly, ref } from "vue";
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* @
|
|
11
|
-
* @property {import("vue").Ref<boolean
|
|
12
|
-
* @property {import("vue").Ref<Error|null>} error - The error that occurred.
|
|
13
|
-
* @property {import("vue").Ref<boolean>} errored - Whether an error has occurred.
|
|
8
|
+
* @typedef {object} LoadingError
|
|
9
|
+
* @property {Readonly<import("vue").Ref<boolean|undefined>>} loading - Whether the component is loading.
|
|
10
|
+
* @property {Readonly<import("vue").Ref<Error|null>>} error - The error that occurred.
|
|
11
|
+
* @property {Readonly<import("vue").Ref<boolean>>} errored - Whether an error has occurred.
|
|
14
12
|
* @property {() => void} setLoading - Set the loading state.
|
|
15
13
|
* @property {() => void} clearLoading - Clear the loading state.
|
|
16
14
|
* @property {(error) => void} setError - Set the error state.
|
|
17
15
|
* @property {() => void} clearError - Clear the error state.
|
|
18
16
|
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* A composable function for managing loading and error states.
|
|
20
|
+
*
|
|
21
|
+
* @returns {LoadingError} - An object containing reactive fields and actions for loading and error states.
|
|
22
|
+
*/
|
|
19
23
|
export function useLoadingError() {
|
|
24
|
+
/** @type {import("vue").Ref<boolean|undefined>} */
|
|
20
25
|
const loading = ref(undefined);
|
|
26
|
+
/** @type {import("vue").Ref<Error|null>} */
|
|
21
27
|
const error = ref(null);
|
|
28
|
+
/** @type {import("vue").Ref<boolean>} */
|
|
22
29
|
const errored = ref(false);
|
|
23
30
|
|
|
24
31
|
return {
|