@data-fair/lib-vue 1.17.0 → 1.18.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/async-action.d.ts +3 -1
- package/async-action.js +6 -0
- package/package.json +1 -1
- package/ui-notif.js +1 -0
package/async-action.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { type Ref } from 'vue';
|
|
2
2
|
import { type PartialUiNotif, type UiNotif } from './ui-notif.js';
|
|
3
|
+
type Finally = () => Promise<void> | void;
|
|
3
4
|
type AsyncActionOptions = {
|
|
4
5
|
error?: string;
|
|
5
6
|
success?: PartialUiNotif;
|
|
6
7
|
catch?: 'error' | 'success' | 'all';
|
|
8
|
+
finally?: Finally;
|
|
7
9
|
};
|
|
8
|
-
export declare function useAsyncAction<F extends (...args: any[]) => Promise<any>>(fn: F, options?: AsyncActionOptions): {
|
|
10
|
+
export declare function useAsyncAction<F extends (...args: any[]) => Promise<any>>(fn: F, options?: AsyncActionOptions | Finally): {
|
|
9
11
|
execute: F;
|
|
10
12
|
notif: Ref<UiNotif | undefined>;
|
|
11
13
|
loading: Ref<boolean>;
|
package/async-action.js
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
import { ref, readonly, shallowReadonly, shallowRef } from 'vue'
|
|
3
3
|
import { useUiNotif, getFullNotif, getErrorMsg } from './ui-notif.js'
|
|
4
4
|
export function useAsyncAction (fn, options) {
|
|
5
|
+
if (typeof options === 'function') {
|
|
6
|
+
options = { finally: options }
|
|
7
|
+
}
|
|
5
8
|
const { sendUiNotif } = useUiNotif()
|
|
6
9
|
const notif = shallowRef()
|
|
7
10
|
const loading = ref(false)
|
|
@@ -30,6 +33,9 @@ export function useAsyncAction (fn, options) {
|
|
|
30
33
|
}
|
|
31
34
|
loading.value = false
|
|
32
35
|
}
|
|
36
|
+
if (options?.finally) {
|
|
37
|
+
await options?.finally()
|
|
38
|
+
}
|
|
33
39
|
}
|
|
34
40
|
return { execute, notif: shallowReadonly(notif), loading: readonly(loading), error: readonly(error) }
|
|
35
41
|
}
|
package/package.json
CHANGED
package/ui-notif.js
CHANGED
|
@@ -63,6 +63,7 @@ export function useUiNotif () {
|
|
|
63
63
|
export default useUiNotif
|
|
64
64
|
export function withUiNotif (fn, errorMsg, successNotif) {
|
|
65
65
|
const { sendUiNotif } = useUiNotif()
|
|
66
|
+
console.warn('withUiNotif is deprecated, use useAsyncAction instead')
|
|
66
67
|
return async function (...args) {
|
|
67
68
|
try {
|
|
68
69
|
const result = await fn(...args)
|