@veltdev/react 4.4.0-beta.3 → 4.4.0-beta.5

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/cjs/index.js CHANGED
@@ -140,7 +140,7 @@ var loadVelt = function (callback, version, staging, develop, proxyDomain) {
140
140
  }
141
141
  };
142
142
 
143
- var VELT_SDK_VERSION = '4.4.0-beta.3';
143
+ var VELT_SDK_VERSION = '4.4.0-beta.5';
144
144
  var VELT_SDK_INIT_EVENT = 'onVeltInit';
145
145
  var VELT_TAB_ID = 'veltTabId';
146
146
 
@@ -6216,17 +6216,17 @@ function useLiveStateData(liveStateDataId, liveStateDataConfig) {
6216
6216
  }, [liveStateSyncElement === null || liveStateSyncElement === void 0 ? void 0 : liveStateSyncElement.getLiveStateData, inputs]);
6217
6217
  return data;
6218
6218
  }
6219
- function useSetLiveStateData(liveStateDataId, liveStateData) {
6219
+ function useSetLiveStateData(liveStateDataId, liveStateData, config) {
6220
6220
  var liveStateSyncElement = useLiveStateSyncUtils();
6221
6221
  // Memoize inputs
6222
6222
  var inputs = React__default["default"].useMemo(function () {
6223
- return { liveStateDataId: liveStateDataId, liveStateData: liveStateData };
6224
- }, [liveStateDataId, JSON.stringify(liveStateData)]);
6223
+ return { liveStateDataId: liveStateDataId, liveStateData: liveStateData, config: config };
6224
+ }, [liveStateDataId, JSON.stringify(liveStateData), JSON.stringify(config)]);
6225
6225
  React__default["default"].useEffect(function () {
6226
6226
  if (!(liveStateSyncElement === null || liveStateSyncElement === void 0 ? void 0 : liveStateSyncElement.setLiveStateData))
6227
6227
  return;
6228
6228
  if (inputs.liveStateDataId && inputs.liveStateData) {
6229
- liveStateSyncElement.setLiveStateData(inputs.liveStateDataId, inputs.liveStateData);
6229
+ liveStateSyncElement.setLiveStateData(inputs.liveStateDataId, inputs.liveStateData, inputs.config);
6230
6230
  }
6231
6231
  }, [liveStateSyncElement === null || liveStateSyncElement === void 0 ? void 0 : liveStateSyncElement.setLiveStateData, inputs]);
6232
6232
  }
@@ -6784,39 +6784,55 @@ var createLiveStateMiddleware = function (config) {
6784
6784
  var isSdkInitialized = false;
6785
6785
  var setupGetDataSubscription = function () {
6786
6786
  var _a, _b;
6787
- if (!dataSubscription && window.Velt && ((_a = window.Velt) === null || _a === void 0 ? void 0 : _a.getLiveStateSyncElement)) {
6788
- var liveStateSyncElement = (_b = window.Velt) === null || _b === void 0 ? void 0 : _b.getLiveStateSyncElement();
6789
- dataSubscription = liveStateSyncElement === null || liveStateSyncElement === void 0 ? void 0 : liveStateSyncElement.getLiveStateData(liveStateDataId).subscribe(function (data) {
6790
- // Dispatch action to update local state, marking it as remote
6791
- if (data) {
6792
- var sessionId_1 = getSessionId();
6793
- if (data.id === sessionId_1) {
6794
- return;
6795
- }
6796
- else {
6797
- internalStore === null || internalStore === void 0 ? void 0 : internalStore.dispatch(__assign(__assign({}, data.action), { isRemote: true }));
6787
+ try {
6788
+ if (!dataSubscription && window.Velt && ((_a = window.Velt) === null || _a === void 0 ? void 0 : _a.getLiveStateSyncElement)) {
6789
+ var liveStateSyncElement = (_b = window.Velt) === null || _b === void 0 ? void 0 : _b.getLiveStateSyncElement();
6790
+ dataSubscription = liveStateSyncElement === null || liveStateSyncElement === void 0 ? void 0 : liveStateSyncElement.getLiveStateData(liveStateDataId).subscribe(function (data) {
6791
+ // Dispatch action to update local state, marking it as remote
6792
+ if (data) {
6793
+ var sessionId_1 = getSessionId();
6794
+ if (data.id === sessionId_1) {
6795
+ return;
6796
+ }
6797
+ else {
6798
+ internalStore === null || internalStore === void 0 ? void 0 : internalStore.dispatch(__assign(__assign({}, data.action), { isRemote: true }));
6799
+ }
6798
6800
  }
6799
- }
6800
- });
6801
+ });
6802
+ }
6803
+ }
6804
+ catch (err) {
6801
6805
  }
6802
6806
  };
6803
6807
  var updateLiveStateDataId = function (newId) {
6804
- liveStateDataId = newId || VELT_DEFAULT_LIVE_STATE_ID;
6805
- if (dataSubscription) {
6806
- dataSubscription.unsubscribe();
6807
- dataSubscription = null;
6808
+ try {
6809
+ liveStateDataId = newId || VELT_DEFAULT_LIVE_STATE_ID;
6810
+ if (dataSubscription) {
6811
+ dataSubscription.unsubscribe();
6812
+ dataSubscription = null;
6813
+ }
6814
+ if (isSdkInitialized) {
6815
+ setupGetDataSubscription();
6816
+ }
6808
6817
  }
6809
- if (isSdkInitialized) {
6810
- setupGetDataSubscription();
6818
+ catch (err) {
6819
+ // handle error
6811
6820
  }
6812
6821
  };
6813
6822
  var middleware = function (store) {
6814
6823
  internalStore = store;
6815
6824
  var veltSdkInitializedListener = function () {
6816
- isSdkInitialized = true;
6817
- setupGetDataSubscription();
6818
- // Remove the event listener after it's triggered
6819
- window.removeEventListener(VELT_SDK_INIT_EVENT, veltSdkInitializedListener);
6825
+ try {
6826
+ if (window.Velt) {
6827
+ isSdkInitialized = true;
6828
+ setupGetDataSubscription();
6829
+ // Remove the event listener after it's triggered
6830
+ window.removeEventListener(VELT_SDK_INIT_EVENT, veltSdkInitializedListener);
6831
+ }
6832
+ }
6833
+ catch (err) {
6834
+ // handle error
6835
+ }
6820
6836
  };
6821
6837
  // Add the event listener for the veltSdkInitialized event
6822
6838
  window.addEventListener(VELT_SDK_INIT_EVENT, veltSdkInitializedListener);
@@ -6836,20 +6852,21 @@ var createLiveStateMiddleware = function (config) {
6836
6852
  };
6837
6853
  };
6838
6854
  var logLiveState = function (action, liveStateDataId) {
6839
- var _a;
6840
- if (window.Velt) {
6841
- var sessionId_2 = getSessionId();
6842
- var liveStateElement = (_a = window === null || window === void 0 ? void 0 : window.Velt) === null || _a === void 0 ? void 0 : _a.getLiveStateSyncElement();
6843
- if (liveStateElement === null || liveStateElement === void 0 ? void 0 : liveStateElement.setLiveStateData) {
6844
- liveStateElement.setLiveStateData(liveStateDataId, {
6845
- id: sessionId_2,
6846
- action: action
6847
- });
6855
+ var _a, _b;
6856
+ try {
6857
+ if (window.Velt && ((_a = window === null || window === void 0 ? void 0 : window.Velt) === null || _a === void 0 ? void 0 : _a.getLiveStateSyncElement)) {
6858
+ var sessionId_2 = getSessionId();
6859
+ var liveStateElement = (_b = window === null || window === void 0 ? void 0 : window.Velt) === null || _b === void 0 ? void 0 : _b.getLiveStateSyncElement();
6860
+ if (liveStateElement === null || liveStateElement === void 0 ? void 0 : liveStateElement.setLiveStateData) {
6861
+ liveStateElement.setLiveStateData(liveStateDataId, {
6862
+ id: sessionId_2,
6863
+ action: action
6864
+ });
6865
+ }
6848
6866
  }
6849
- liveStateElement.setLiveStateData(liveStateDataId, {
6850
- id: sessionId_2,
6851
- action: action
6852
- });
6867
+ }
6868
+ catch (err) {
6869
+ // handle error
6853
6870
  }
6854
6871
  };
6855
6872