@data-fair/lib-vue 1.16.0 → 1.18.0

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 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>;
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/fetch.d.ts CHANGED
@@ -4,6 +4,7 @@ type UseFetchOptions = {
4
4
  query?: QueryObject | Ref<QueryObject>;
5
5
  watch?: Boolean;
6
6
  notifError?: Boolean;
7
+ immediate?: Boolean;
7
8
  };
8
9
  type OptionalUrl = string | null | undefined;
9
10
  export declare function useFetch<T>(url: OptionalUrl | Ref<OptionalUrl> | (() => OptionalUrl), options?: UseFetchOptions): {
package/fetch.js CHANGED
@@ -18,8 +18,8 @@ export function useFetch (url, options = {}) {
18
18
  const error = shallowRef(null)
19
19
  let abortController
20
20
  const refresh = async () => {
21
- if (!fullUrl.value) { return null }
22
21
  initialized.value = true
22
+ if (!fullUrl.value) { return null }
23
23
  error.value = null
24
24
  if (abortController) { abortController.abort() }
25
25
  loading.value = true
@@ -38,7 +38,9 @@ export function useFetch (url, options = {}) {
38
38
  return data.value
39
39
  }
40
40
  if (options.watch !== false) {
41
- watch(fullUrl, refresh, { immediate: true })
41
+ watch(fullUrl, () => {
42
+ if (options.immediate !== false || initialized.value) { refresh() }
43
+ }, { immediate: true })
42
44
  }
43
45
  return {
44
46
  initialized: readonly(initialized),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@data-fair/lib-vue",
3
- "version": "1.16.0",
3
+ "version": "1.18.0",
4
4
  "description": "Composables and other utilities for Vue applications in the data-fair stack.",
5
5
  "main": "index.js",
6
6
  "files": [
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)