@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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ciwergrp/nuxid",
3
3
  "configKey": "nuxid",
4
- "version": "1.17.0",
4
+ "version": "1.17.1",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -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
- void init();
202
- } else {
203
- const asyncKey = key ?? `cursor:${String(url)}:${JSON.stringify(currentParams.value ?? {})}`;
204
- try {
205
- const { useAsyncData } = await import("#app");
206
- loading.value = true;
207
- const { data: asyncData, error: asyncError } = await useAsyncData(
208
- asyncKey,
209
- () => fetcherFn(initialUrl, currentParams.value)
210
- );
211
- loading.value = false;
212
- if (asyncData.value) {
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
- if (asyncError.value) {
219
- error.value = normalizeFetchError(asyncError.value);
215
+ });
216
+ watch(asyncError, (val) => {
217
+ if (val) {
218
+ error.value = normalizeFetchError(val);
220
219
  }
221
- } catch {
222
- await init();
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ciwergrp/nuxid",
3
- "version": "1.17.0",
3
+ "version": "1.17.1",
4
4
  "description": "All-in-one essential modules for Nuxt",
5
5
  "repository": {
6
6
  "type": "git",