@merkaly/nuxt 0.13.2 → 0.13.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/dist/module.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getCurrentInstance, onServerPrefetch, reactive, ref, useNuxtApp, useState } from "#imports";
|
|
2
2
|
function useApi(callback) {
|
|
3
3
|
const { $api } = useNuxtApp();
|
|
4
|
-
|
|
4
|
+
let controller = new AbortController();
|
|
5
5
|
const params = reactive({});
|
|
6
6
|
const getOptions = (currentParams) => {
|
|
7
7
|
const options = callback(currentParams);
|
|
@@ -23,6 +23,8 @@ function useApi(callback) {
|
|
|
23
23
|
params[key2] = args[key2];
|
|
24
24
|
});
|
|
25
25
|
const currentOptions = getOptions(params);
|
|
26
|
+
controller = new AbortController();
|
|
27
|
+
loading.value = true;
|
|
26
28
|
await $api(currentOptions.uri, {
|
|
27
29
|
...currentOptions,
|
|
28
30
|
controller,
|
|
@@ -32,10 +34,7 @@ function useApi(callback) {
|
|
|
32
34
|
loading,
|
|
33
35
|
meta,
|
|
34
36
|
params
|
|
35
|
-
}).
|
|
36
|
-
loading.value = false;
|
|
37
|
-
throw reason;
|
|
38
|
-
});
|
|
37
|
+
}).finally(() => loading.value = false);
|
|
39
38
|
};
|
|
40
39
|
if (initialOptions.immediate) {
|
|
41
40
|
const instance = getCurrentInstance();
|
|
@@ -22,7 +22,7 @@ const resolveLoader = async (nuxtApp, loader) => {
|
|
|
22
22
|
const result = await nuxtApp.runWithContext(loader);
|
|
23
23
|
if (!isAdapter(result)) return result;
|
|
24
24
|
if (result.loading.value) await until(result.loading).toBe(false);
|
|
25
|
-
else await result.execute();
|
|
25
|
+
else await nuxtApp.runWithContext(() => result.execute());
|
|
26
26
|
if (result.error.value) throw result.error.value;
|
|
27
27
|
if (result.data.value == null) throw new Error("Empty response");
|
|
28
28
|
return result.data.value;
|