@wlloyalty/wll-react-sdk 1.1.0 → 1.2.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/native.js CHANGED
@@ -3739,39 +3739,50 @@ var useGroupRefresh = function (_a) {
3739
3739
  }, [id, sdk, enabled, setGroupData]);
3740
3740
  };
3741
3741
 
3742
+ var inFlightRequests = new Map();
3742
3743
  var useInitialGroupFetch = function (_a) {
3743
3744
  var id = _a.id, setGroupData = _a.setGroupData;
3744
3745
  var sdk = useWllSdk();
3745
3746
  var _b = React.useState(true), isLoading = _b[0], setIsLoading = _b[1];
3746
3747
  var _c = React.useState(null), error = _c[0], setError = _c[1];
3747
3748
  React.useEffect(function () {
3749
+ if (!id || !(sdk === null || sdk === void 0 ? void 0 : sdk.refreshGroup)) {
3750
+ setError('Unable to fetch group data: invalid configuration');
3751
+ setIsLoading(false);
3752
+ return;
3753
+ }
3748
3754
  var cancelled = false;
3749
- var fetchGroup = function () { return __awaiter(void 0, void 0, void 0, function () {
3750
- var response;
3755
+ var fetch = function () { return __awaiter(void 0, void 0, void 0, function () {
3756
+ var existing, request, res;
3751
3757
  var _b;
3752
3758
  return __generator(this, function (_c) {
3753
3759
  switch (_c.label) {
3754
3760
  case 0:
3755
- if (!id || !(sdk === null || sdk === void 0 ? void 0 : sdk.refreshGroup)) {
3756
- setError('Unable to fetch group data: invalid configuration');
3757
- setIsLoading(false);
3758
- return [2 /*return*/];
3759
- }
3760
3761
  setIsLoading(true);
3761
3762
  setError(null);
3763
+ existing = inFlightRequests.get(id);
3764
+ request = existing !== null && existing !== void 0 ? existing : sdk.refreshGroup(id);
3765
+ if (!existing) {
3766
+ inFlightRequests.set(id, request);
3767
+ request.finally(function () {
3768
+ if (inFlightRequests.get(id) === request) {
3769
+ inFlightRequests.delete(id);
3770
+ }
3771
+ });
3772
+ }
3762
3773
  _c.label = 1;
3763
3774
  case 1:
3764
3775
  _c.trys.push([1, 3, 4, 5]);
3765
- return [4 /*yield*/, sdk.refreshGroup(id)];
3776
+ return [4 /*yield*/, request];
3766
3777
  case 2:
3767
- response = _c.sent();
3778
+ res = _c.sent();
3768
3779
  if (cancelled)
3769
3780
  return [2 /*return*/];
3770
- if ((response === null || response === void 0 ? void 0 : response.status) === 'success' && response.data) {
3771
- setGroupData(response.data);
3781
+ if ((res === null || res === void 0 ? void 0 : res.status) === 'success' && res.data) {
3782
+ setGroupData(res.data);
3772
3783
  }
3773
3784
  else {
3774
- setError((_b = response === null || response === void 0 ? void 0 : response.error) !== null && _b !== void 0 ? _b : 'Failed to fetch group data');
3785
+ setError((_b = res === null || res === void 0 ? void 0 : res.error) !== null && _b !== void 0 ? _b : 'Failed to fetch group data');
3775
3786
  }
3776
3787
  return [3 /*break*/, 5];
3777
3788
  case 3:
@@ -3787,7 +3798,7 @@ var useInitialGroupFetch = function (_a) {
3787
3798
  }
3788
3799
  });
3789
3800
  }); };
3790
- fetchGroup();
3801
+ fetch();
3791
3802
  return function () {
3792
3803
  cancelled = true;
3793
3804
  };