@ciwergrp/nuxid 1.17.0 → 1.17.2
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 +42 -25
- package/package.json +1 -1
package/dist/module.json
CHANGED
|
@@ -69,7 +69,7 @@ export async function useCursorHttp(url, options) {
|
|
|
69
69
|
const hasNextPage = ref(true);
|
|
70
70
|
const isLoadMoreTriggered = ref(false);
|
|
71
71
|
const currentParams = shallowRef(
|
|
72
|
-
unwrapReactiveObject(fetchOptions)
|
|
72
|
+
unwrapReactiveObject(fetchOptions) ?? {}
|
|
73
73
|
);
|
|
74
74
|
let pollTimer = null;
|
|
75
75
|
let fetchPromise = null;
|
|
@@ -158,10 +158,14 @@ export async function useCursorHttp(url, options) {
|
|
|
158
158
|
return;
|
|
159
159
|
}
|
|
160
160
|
isLoadMoreTriggered.value = true;
|
|
161
|
+
const baseParams = currentParams.value ?? {};
|
|
161
162
|
const params = nextCursor.value ? {
|
|
162
|
-
...
|
|
163
|
-
query: {
|
|
164
|
-
|
|
163
|
+
...baseParams,
|
|
164
|
+
query: {
|
|
165
|
+
...baseParams.query ?? {},
|
|
166
|
+
[resolvedCursorParam]: nextCursor.value
|
|
167
|
+
}
|
|
168
|
+
} : baseParams;
|
|
165
169
|
await fetchData(initialUrl, params);
|
|
166
170
|
};
|
|
167
171
|
const refresh = async () => {
|
|
@@ -182,7 +186,7 @@ export async function useCursorHttp(url, options) {
|
|
|
182
186
|
watch(
|
|
183
187
|
reactiveSources,
|
|
184
188
|
() => {
|
|
185
|
-
currentParams.value = unwrapReactiveObject(fetchOptions);
|
|
189
|
+
currentParams.value = unwrapReactiveObject(fetchOptions) ?? {};
|
|
186
190
|
refresh();
|
|
187
191
|
},
|
|
188
192
|
{ flush: "sync" }
|
|
@@ -197,29 +201,42 @@ export async function useCursorHttp(url, options) {
|
|
|
197
201
|
}
|
|
198
202
|
});
|
|
199
203
|
if (immediate) {
|
|
204
|
+
const asyncKey = key ?? `cursor:${String(url)}:${JSON.stringify(currentParams.value ?? {})}`;
|
|
200
205
|
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;
|
|
206
|
+
const { data: asyncData, error: asyncError, pending: asyncPending } = useAsyncData(
|
|
207
|
+
asyncKey,
|
|
208
|
+
() => fetcherFn(initialUrl, currentParams.value),
|
|
209
|
+
{ lazy: true }
|
|
210
|
+
);
|
|
211
|
+
watch(asyncPending, (v) => loading.value = v, { immediate: true });
|
|
212
|
+
watch(asyncData, (val) => {
|
|
213
|
+
if (val) {
|
|
214
|
+
const response = val;
|
|
215
|
+
data.value = { ...response, data: [...response.data] };
|
|
216
|
+
nextCursor.value = normalizeCursorValue(response.meta?.[cursorKey]);
|
|
217
|
+
hasNextPage.value = response.meta?.[hasMoreKey] ?? false;
|
|
217
218
|
}
|
|
218
|
-
|
|
219
|
-
|
|
219
|
+
});
|
|
220
|
+
watch(asyncError, (val) => {
|
|
221
|
+
if (val) {
|
|
222
|
+
error.value = normalizeFetchError(val);
|
|
220
223
|
}
|
|
221
|
-
}
|
|
222
|
-
|
|
224
|
+
});
|
|
225
|
+
} else {
|
|
226
|
+
loading.value = true;
|
|
227
|
+
const { data: asyncData, error: asyncError } = await useAsyncData(
|
|
228
|
+
asyncKey,
|
|
229
|
+
() => fetcherFn(initialUrl, currentParams.value)
|
|
230
|
+
);
|
|
231
|
+
loading.value = false;
|
|
232
|
+
if (asyncData.value) {
|
|
233
|
+
const val = asyncData.value;
|
|
234
|
+
data.value = { ...val, data: [...val.data] };
|
|
235
|
+
nextCursor.value = normalizeCursorValue(val.meta?.[cursorKey]);
|
|
236
|
+
hasNextPage.value = val.meta?.[hasMoreKey] ?? false;
|
|
237
|
+
}
|
|
238
|
+
if (asyncError.value) {
|
|
239
|
+
error.value = normalizeFetchError(asyncError.value);
|
|
223
240
|
}
|
|
224
241
|
}
|
|
225
242
|
}
|