@absolutejs/absolute 0.19.0-beta.336 → 0.19.0-beta.338

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.
@@ -39746,23 +39746,45 @@ var initializeIslandStores = (state) => {
39746
39746
  };
39747
39747
  globalThis.__ABS_ISLAND_STATE__ = nextSnapshot;
39748
39748
  for (const [storeId, store] of getIslandStores()) {
39749
- applySnapshot(store, nextSnapshot[storeId]);
39749
+ for (const instance of store) {
39750
+ instance.applyExternalSnapshot(nextSnapshot[storeId] ?? {});
39751
+ }
39750
39752
  }
39751
39753
  };
39752
- var createIslandStore = (storeId) => (createState) => {
39754
+ var createIslandStore = (storeId, createState) => {
39755
+ const store = createStore(createState);
39753
39756
  const stores = getIslandStores();
39754
- const existingStore = stores.get(storeId);
39755
- if (existingStore) {
39756
- return existingStore;
39757
- }
39758
- const store = createStore()(createState);
39757
+ const storeInstances = stores.get(storeId) ?? new Set;
39759
39758
  const initialSnapshot = getIslandStoreSnapshot()[storeId];
39760
39759
  applySnapshot(store, initialSnapshot);
39761
- getIslandStoreSnapshot()[storeId] = toSerializableState(store.getState());
39760
+ let isApplyingExternalSnapshot = false;
39761
+ const applyExternalSnapshot = (snapshot) => {
39762
+ isApplyingExternalSnapshot = true;
39763
+ applySnapshot(store, snapshot);
39764
+ };
39765
+ const syncSnapshot = (state) => {
39766
+ const nextSnapshot = toSerializableState(state);
39767
+ getIslandStoreSnapshot()[storeId] = nextSnapshot;
39768
+ for (const peerStore of storeInstances) {
39769
+ if (peerStore.store === store) {
39770
+ continue;
39771
+ }
39772
+ peerStore.applyExternalSnapshot(nextSnapshot);
39773
+ }
39774
+ };
39775
+ storeInstances.add({
39776
+ applyExternalSnapshot,
39777
+ store
39778
+ });
39779
+ stores.set(storeId, storeInstances);
39780
+ syncSnapshot(store.getState());
39762
39781
  store.subscribe((state) => {
39763
- getIslandStoreSnapshot()[storeId] = toSerializableState(state);
39782
+ if (isApplyingExternalSnapshot) {
39783
+ isApplyingExternalSnapshot = false;
39784
+ return;
39785
+ }
39786
+ syncSnapshot(state);
39764
39787
  });
39765
- stores.set(storeId, store);
39766
39788
  return store;
39767
39789
  };
39768
39790
  var readIslandStore = (store, selector) => selector(store.getState());
@@ -39809,5 +39831,5 @@ export {
39809
39831
  Island
39810
39832
  };
39811
39833
 
39812
- //# debugId=B0FCCDB646127B3764756E2164756E21
39834
+ //# debugId=9C699B2B9235EC6A64756E2164756E21
39813
39835
  //# sourceMappingURL=index.js.map