@faasjs/react 6.9.0 → 6.11.0

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/index.cjs CHANGED
@@ -217,6 +217,8 @@ function useFaas(action, defaultParams, options = {}) {
217
217
  );
218
218
  const promiseRef = react.useRef(null);
219
219
  const controllerRef = react.useRef(null);
220
+ const pendingReloadsRef = react.useRef(/* @__PURE__ */ new Map());
221
+ const reloadCounterRef = react.useRef(0);
220
222
  useEqualEffect(() => {
221
223
  setSkip(
222
224
  typeof options.skip === "function" ? options.skip(params) : options.skip
@@ -245,6 +247,9 @@ function useFaas(action, defaultParams, options = {}) {
245
247
  request.then((r) => {
246
248
  options.setData ? options.setData(r.data) : setData(r.data);
247
249
  setLoading(false);
250
+ for (const { resolve } of pendingReloadsRef.current.values())
251
+ resolve(r.data);
252
+ pendingReloadsRef.current.clear();
248
253
  }).catch(async (e) => {
249
254
  if (typeof e?.message === "string" && e.message.toLowerCase().indexOf("aborted") >= 0)
250
255
  return;
@@ -261,6 +266,8 @@ function useFaas(action, defaultParams, options = {}) {
261
266
  }
262
267
  else setError(e);
263
268
  setLoading(false);
269
+ for (const { reject } of pendingReloadsRef.current.values()) reject(e);
270
+ pendingReloadsRef.current.clear();
264
271
  return Promise.reject(e);
265
272
  });
266
273
  }
@@ -282,8 +289,12 @@ function useFaas(action, defaultParams, options = {}) {
282
289
  (params2) => {
283
290
  if (skip) setSkip(false);
284
291
  if (params2) setParams(params2);
292
+ const reloadCounter = ++reloadCounterRef.current;
285
293
  setReloadTimes((prev) => prev + 1);
286
- return promiseRef.current;
294
+ return new Promise((resolve, reject) => {
295
+ pendingReloadsRef.current.set(reloadCounter, { resolve, reject });
296
+ setReloadTimes((prev) => prev + 1);
297
+ });
287
298
  },
288
299
  [params, skip]
289
300
  );
package/dist/index.mjs CHANGED
@@ -215,6 +215,8 @@ function useFaas(action, defaultParams, options = {}) {
215
215
  );
216
216
  const promiseRef = useRef(null);
217
217
  const controllerRef = useRef(null);
218
+ const pendingReloadsRef = useRef(/* @__PURE__ */ new Map());
219
+ const reloadCounterRef = useRef(0);
218
220
  useEqualEffect(() => {
219
221
  setSkip(
220
222
  typeof options.skip === "function" ? options.skip(params) : options.skip
@@ -243,6 +245,9 @@ function useFaas(action, defaultParams, options = {}) {
243
245
  request.then((r) => {
244
246
  options.setData ? options.setData(r.data) : setData(r.data);
245
247
  setLoading(false);
248
+ for (const { resolve } of pendingReloadsRef.current.values())
249
+ resolve(r.data);
250
+ pendingReloadsRef.current.clear();
246
251
  }).catch(async (e) => {
247
252
  if (typeof e?.message === "string" && e.message.toLowerCase().indexOf("aborted") >= 0)
248
253
  return;
@@ -259,6 +264,8 @@ function useFaas(action, defaultParams, options = {}) {
259
264
  }
260
265
  else setError(e);
261
266
  setLoading(false);
267
+ for (const { reject } of pendingReloadsRef.current.values()) reject(e);
268
+ pendingReloadsRef.current.clear();
262
269
  return Promise.reject(e);
263
270
  });
264
271
  }
@@ -280,8 +287,12 @@ function useFaas(action, defaultParams, options = {}) {
280
287
  (params2) => {
281
288
  if (skip) setSkip(false);
282
289
  if (params2) setParams(params2);
290
+ const reloadCounter = ++reloadCounterRef.current;
283
291
  setReloadTimes((prev) => prev + 1);
284
- return promiseRef.current;
292
+ return new Promise((resolve, reject) => {
293
+ pendingReloadsRef.current.set(reloadCounter, { resolve, reject });
294
+ setReloadTimes((prev) => prev + 1);
295
+ });
285
296
  },
286
297
  [params, skip]
287
298
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/react",
3
- "version": "6.9.0",
3
+ "version": "6.11.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -30,10 +30,10 @@
30
30
  "dist"
31
31
  ],
32
32
  "peerDependencies": {
33
- "@faasjs/browser": "6.9.0"
33
+ "@faasjs/browser": ">=6.11.0"
34
34
  },
35
35
  "devDependencies": {
36
- "@faasjs/browser": "6.9.0",
36
+ "@faasjs/browser": ">=6.11.0",
37
37
  "@types/react": "*",
38
38
  "react": "*"
39
39
  },