@ciwergrp/nuxid 1.17.0 → 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 +1 -1
- package/dist/runtime/fetcher/cursor.js +33 -20
- package/package.json +1 -1
package/dist/module.json
CHANGED
|
@@ -197,29 +197,42 @@ export async function useCursorHttp(url, options) {
|
|
|
197
197
|
}
|
|
198
198
|
});
|
|
199
199
|
if (immediate) {
|
|
200
|
+
const asyncKey = key ?? `cursor:${String(url)}:${JSON.stringify(currentParams.value ?? {})}`;
|
|
200
201
|
if (lazy) {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
const val = asyncData.value;
|
|
214
|
-
data.value = { ...val, data: [...val.data] };
|
|
215
|
-
nextCursor.value = normalizeCursorValue(val.meta?.[cursorKey]);
|
|
216
|
-
hasNextPage.value = val.meta?.[hasMoreKey] ?? false;
|
|
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;
|
|
217
214
|
}
|
|
218
|
-
|
|
219
|
-
|
|
215
|
+
});
|
|
216
|
+
watch(asyncError, (val) => {
|
|
217
|
+
if (val) {
|
|
218
|
+
error.value = normalizeFetchError(val);
|
|
220
219
|
}
|
|
221
|
-
}
|
|
222
|
-
|
|
220
|
+
});
|
|
221
|
+
} else {
|
|
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);
|
|
223
236
|
}
|
|
224
237
|
}
|
|
225
238
|
}
|