@ciwergrp/nuxid 1.17.1 → 1.17.3
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 +1 -1
- package/dist/runtime/fetcher/cursor.js +21 -51
- package/package.json +1 -1
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 key in obj) {
|
|
9
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
10
|
+
const value = obj[key];
|
|
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 key in obj) {
|
|
26
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
27
|
+
const value = obj[key];
|
|
28
28
|
if (isRef(value)) {
|
|
29
|
-
unwrapped[
|
|
29
|
+
unwrapped[key] = value.value;
|
|
30
30
|
} else if (typeof value === "object") {
|
|
31
|
-
unwrapped[
|
|
31
|
+
unwrapped[key] = unwrapReactiveObject(value);
|
|
32
32
|
} else {
|
|
33
|
-
unwrapped[
|
|
33
|
+
unwrapped[key] = value;
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -58,8 +58,7 @@ export async function useCursorHttp(url, options) {
|
|
|
58
58
|
fetchOptions,
|
|
59
59
|
meta,
|
|
60
60
|
itemKey = "id",
|
|
61
|
-
cursorParam = "cursor"
|
|
62
|
-
key
|
|
61
|
+
cursorParam = "cursor"
|
|
63
62
|
} = options ?? {};
|
|
64
63
|
const initialUrl = url;
|
|
65
64
|
const data = ref();
|
|
@@ -69,7 +68,7 @@ export async function useCursorHttp(url, options) {
|
|
|
69
68
|
const hasNextPage = ref(true);
|
|
70
69
|
const isLoadMoreTriggered = ref(false);
|
|
71
70
|
const currentParams = shallowRef(
|
|
72
|
-
unwrapReactiveObject(fetchOptions)
|
|
71
|
+
unwrapReactiveObject(fetchOptions) ?? {}
|
|
73
72
|
);
|
|
74
73
|
let pollTimer = null;
|
|
75
74
|
let fetchPromise = null;
|
|
@@ -158,10 +157,14 @@ export async function useCursorHttp(url, options) {
|
|
|
158
157
|
return;
|
|
159
158
|
}
|
|
160
159
|
isLoadMoreTriggered.value = true;
|
|
160
|
+
const baseParams = currentParams.value ?? {};
|
|
161
161
|
const params = nextCursor.value ? {
|
|
162
|
-
...
|
|
163
|
-
query: {
|
|
164
|
-
|
|
162
|
+
...baseParams,
|
|
163
|
+
query: {
|
|
164
|
+
...baseParams.query ?? {},
|
|
165
|
+
[resolvedCursorParam]: nextCursor.value
|
|
166
|
+
}
|
|
167
|
+
} : baseParams;
|
|
165
168
|
await fetchData(initialUrl, params);
|
|
166
169
|
};
|
|
167
170
|
const refresh = async () => {
|
|
@@ -182,7 +185,7 @@ export async function useCursorHttp(url, options) {
|
|
|
182
185
|
watch(
|
|
183
186
|
reactiveSources,
|
|
184
187
|
() => {
|
|
185
|
-
currentParams.value = unwrapReactiveObject(fetchOptions);
|
|
188
|
+
currentParams.value = unwrapReactiveObject(fetchOptions) ?? {};
|
|
186
189
|
refresh();
|
|
187
190
|
},
|
|
188
191
|
{ flush: "sync" }
|
|
@@ -197,43 +200,10 @@ export async function useCursorHttp(url, options) {
|
|
|
197
200
|
}
|
|
198
201
|
});
|
|
199
202
|
if (immediate) {
|
|
200
|
-
const asyncKey = key ?? `cursor:${String(url)}:${JSON.stringify(currentParams.value ?? {})}`;
|
|
201
203
|
if (lazy) {
|
|
202
|
-
|
|
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
|
-
});
|
|
204
|
+
void fetchData(initialUrl, currentParams.value);
|
|
221
205
|
} else {
|
|
222
|
-
|
|
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
|
-
}
|
|
206
|
+
await fetchData(initialUrl, currentParams.value);
|
|
237
207
|
}
|
|
238
208
|
}
|
|
239
209
|
return {
|