@ciwergrp/nuxid 1.16.7 → 1.17.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/dist/module.json
CHANGED
|
@@ -5,9 +5,9 @@ export async function useCursorHttp(url, options) {
|
|
|
5
5
|
if (!obj || typeof obj !== "object") {
|
|
6
6
|
return sources;
|
|
7
7
|
}
|
|
8
|
-
for (const
|
|
9
|
-
if (Object.prototype.hasOwnProperty.call(obj,
|
|
10
|
-
const value = obj[
|
|
8
|
+
for (const key2 in obj) {
|
|
9
|
+
if (Object.prototype.hasOwnProperty.call(obj, key2)) {
|
|
10
|
+
const value = obj[key2];
|
|
11
11
|
if (isRef(value)) {
|
|
12
12
|
sources.push(value);
|
|
13
13
|
} else if (typeof value === "object") {
|
|
@@ -22,15 +22,15 @@ export async function useCursorHttp(url, options) {
|
|
|
22
22
|
return obj;
|
|
23
23
|
}
|
|
24
24
|
const unwrapped = Array.isArray(obj) ? [] : {};
|
|
25
|
-
for (const
|
|
26
|
-
if (Object.prototype.hasOwnProperty.call(obj,
|
|
27
|
-
const value = obj[
|
|
25
|
+
for (const key2 in obj) {
|
|
26
|
+
if (Object.prototype.hasOwnProperty.call(obj, key2)) {
|
|
27
|
+
const value = obj[key2];
|
|
28
28
|
if (isRef(value)) {
|
|
29
|
-
unwrapped[
|
|
29
|
+
unwrapped[key2] = value.value;
|
|
30
30
|
} else if (typeof value === "object") {
|
|
31
|
-
unwrapped[
|
|
31
|
+
unwrapped[key2] = unwrapReactiveObject(value);
|
|
32
32
|
} else {
|
|
33
|
-
unwrapped[
|
|
33
|
+
unwrapped[key2] = value;
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -58,7 +58,8 @@ export async function useCursorHttp(url, options) {
|
|
|
58
58
|
fetchOptions,
|
|
59
59
|
meta,
|
|
60
60
|
itemKey = "id",
|
|
61
|
-
cursorParam = "cursor"
|
|
61
|
+
cursorParam = "cursor",
|
|
62
|
+
key
|
|
62
63
|
} = options ?? {};
|
|
63
64
|
const initialUrl = url;
|
|
64
65
|
const data = ref();
|
|
@@ -196,10 +197,43 @@ export async function useCursorHttp(url, options) {
|
|
|
196
197
|
}
|
|
197
198
|
});
|
|
198
199
|
if (immediate) {
|
|
200
|
+
const asyncKey = key ?? `cursor:${String(url)}:${JSON.stringify(currentParams.value ?? {})}`;
|
|
199
201
|
if (lazy) {
|
|
200
|
-
|
|
202
|
+
const { data: asyncData, error: asyncError, pending: asyncPending } = useAsyncData(
|
|
203
|
+
asyncKey,
|
|
204
|
+
() => fetcherFn(initialUrl, currentParams.value),
|
|
205
|
+
{ lazy: true }
|
|
206
|
+
);
|
|
207
|
+
watch(asyncPending, (v) => loading.value = v, { immediate: true });
|
|
208
|
+
watch(asyncData, (val) => {
|
|
209
|
+
if (val) {
|
|
210
|
+
const response = val;
|
|
211
|
+
data.value = { ...response, data: [...response.data] };
|
|
212
|
+
nextCursor.value = normalizeCursorValue(response.meta?.[cursorKey]);
|
|
213
|
+
hasNextPage.value = response.meta?.[hasMoreKey] ?? false;
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
watch(asyncError, (val) => {
|
|
217
|
+
if (val) {
|
|
218
|
+
error.value = normalizeFetchError(val);
|
|
219
|
+
}
|
|
220
|
+
});
|
|
201
221
|
} else {
|
|
202
|
-
|
|
222
|
+
loading.value = true;
|
|
223
|
+
const { data: asyncData, error: asyncError } = await useAsyncData(
|
|
224
|
+
asyncKey,
|
|
225
|
+
() => fetcherFn(initialUrl, currentParams.value)
|
|
226
|
+
);
|
|
227
|
+
loading.value = false;
|
|
228
|
+
if (asyncData.value) {
|
|
229
|
+
const val = asyncData.value;
|
|
230
|
+
data.value = { ...val, data: [...val.data] };
|
|
231
|
+
nextCursor.value = normalizeCursorValue(val.meta?.[cursorKey]);
|
|
232
|
+
hasNextPage.value = val.meta?.[hasMoreKey] ?? false;
|
|
233
|
+
}
|
|
234
|
+
if (asyncError.value) {
|
|
235
|
+
error.value = normalizeFetchError(asyncError.value);
|
|
236
|
+
}
|
|
203
237
|
}
|
|
204
238
|
}
|
|
205
239
|
return {
|