@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.
@@ -29933,23 +29933,45 @@ var initializeIslandStores = (state) => {
29933
29933
  };
29934
29934
  globalThis.__ABS_ISLAND_STATE__ = nextSnapshot;
29935
29935
  for (const [storeId, store] of getIslandStores()) {
29936
- applySnapshot(store, nextSnapshot[storeId]);
29936
+ for (const instance of store) {
29937
+ instance.applyExternalSnapshot(nextSnapshot[storeId] ?? {});
29938
+ }
29937
29939
  }
29938
29940
  };
29939
- var createIslandStore = (storeId) => (createState) => {
29941
+ var createIslandStore = (storeId, createState) => {
29942
+ const store = createStore(createState);
29940
29943
  const stores = getIslandStores();
29941
- const existingStore = stores.get(storeId);
29942
- if (existingStore) {
29943
- return existingStore;
29944
- }
29945
- const store = createStore()(createState);
29944
+ const storeInstances = stores.get(storeId) ?? new Set;
29946
29945
  const initialSnapshot = getIslandStoreSnapshot()[storeId];
29947
29946
  applySnapshot(store, initialSnapshot);
29948
- getIslandStoreSnapshot()[storeId] = toSerializableState(store.getState());
29947
+ let isApplyingExternalSnapshot = false;
29948
+ const applyExternalSnapshot = (snapshot) => {
29949
+ isApplyingExternalSnapshot = true;
29950
+ applySnapshot(store, snapshot);
29951
+ };
29952
+ const syncSnapshot = (state) => {
29953
+ const nextSnapshot = toSerializableState(state);
29954
+ getIslandStoreSnapshot()[storeId] = nextSnapshot;
29955
+ for (const peerStore of storeInstances) {
29956
+ if (peerStore.store === store) {
29957
+ continue;
29958
+ }
29959
+ peerStore.applyExternalSnapshot(nextSnapshot);
29960
+ }
29961
+ };
29962
+ storeInstances.add({
29963
+ applyExternalSnapshot,
29964
+ store
29965
+ });
29966
+ stores.set(storeId, storeInstances);
29967
+ syncSnapshot(store.getState());
29949
29968
  store.subscribe((state) => {
29950
- getIslandStoreSnapshot()[storeId] = toSerializableState(state);
29969
+ if (isApplyingExternalSnapshot) {
29970
+ isApplyingExternalSnapshot = false;
29971
+ return;
29972
+ }
29973
+ syncSnapshot(state);
29951
29974
  });
29952
- stores.set(storeId, store);
29953
29975
  return store;
29954
29976
  };
29955
29977
  var readIslandStore = (store, selector) => selector(store.getState());
@@ -30236,5 +30258,5 @@ export {
30236
30258
  createIslandManifestResolver
30237
30259
  };
30238
30260
 
30239
- //# debugId=4E2FF1E2436F6DF964756E2164756E21
30261
+ //# debugId=EA1E2AFA54A352E864756E2164756E21
30240
30262
  //# sourceMappingURL=index.js.map