@absolutejs/absolute 0.19.0-beta.337 → 0.19.0-beta.339

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,31 +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()((set, get, api) => createState((update) => {
29946
- set((state) => {
29947
- const nextPartial = typeof update === "function" ? update(state) : update;
29948
- return {
29949
- ...state,
29950
- ...nextPartial
29951
- };
29952
- });
29953
- }, get, api));
29944
+ const storeInstances = stores.get(storeId) ?? new Set;
29954
29945
  const initialSnapshot = getIslandStoreSnapshot()[storeId];
29955
29946
  applySnapshot(store, initialSnapshot);
29956
- 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());
29957
29968
  store.subscribe((state) => {
29958
- getIslandStoreSnapshot()[storeId] = toSerializableState(state);
29969
+ if (isApplyingExternalSnapshot) {
29970
+ isApplyingExternalSnapshot = false;
29971
+ return;
29972
+ }
29973
+ syncSnapshot(state);
29959
29974
  });
29960
- stores.set(storeId, store);
29961
29975
  return store;
29962
29976
  };
29963
29977
  var readIslandStore = (store, selector) => selector(store.getState());
@@ -30244,5 +30258,5 @@ export {
30244
30258
  createIslandManifestResolver
30245
30259
  };
30246
30260
 
30247
- //# debugId=ED02FF0864132D5064756E2164756E21
30261
+ //# debugId=EA1E2AFA54A352E864756E2164756E21
30248
30262
  //# sourceMappingURL=index.js.map