@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.
@@ -39746,31 +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()((set, get, api) => createState((update) => {
39759
- set((state) => {
39760
- const nextPartial = typeof update === "function" ? update(state) : update;
39761
- return {
39762
- ...state,
39763
- ...nextPartial
39764
- };
39765
- });
39766
- }, get, api));
39757
+ const storeInstances = stores.get(storeId) ?? new Set;
39767
39758
  const initialSnapshot = getIslandStoreSnapshot()[storeId];
39768
39759
  applySnapshot(store, initialSnapshot);
39769
- 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());
39770
39781
  store.subscribe((state) => {
39771
- getIslandStoreSnapshot()[storeId] = toSerializableState(state);
39782
+ if (isApplyingExternalSnapshot) {
39783
+ isApplyingExternalSnapshot = false;
39784
+ return;
39785
+ }
39786
+ syncSnapshot(state);
39772
39787
  });
39773
- stores.set(storeId, store);
39774
39788
  return store;
39775
39789
  };
39776
39790
  var readIslandStore = (store, selector) => selector(store.getState());
@@ -39817,5 +39831,5 @@ export {
39817
39831
  Island
39818
39832
  };
39819
39833
 
39820
- //# debugId=A81F267E47B9578264756E2164756E21
39834
+ //# debugId=9C699B2B9235EC6A64756E2164756E21
39821
39835
  //# sourceMappingURL=index.js.map