@absolutejs/absolute 0.19.0-beta.337 → 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.
@@ -38504,31 +38504,45 @@ var initializeIslandStores = (state) => {
38504
38504
  };
38505
38505
  globalThis.__ABS_ISLAND_STATE__ = nextSnapshot;
38506
38506
  for (const [storeId, store] of getIslandStores()) {
38507
- applySnapshot(store, nextSnapshot[storeId]);
38507
+ for (const instance of store) {
38508
+ instance.applyExternalSnapshot(nextSnapshot[storeId] ?? {});
38509
+ }
38508
38510
  }
38509
38511
  };
38510
- var createIslandStore = (storeId) => (createState) => {
38512
+ var createIslandStore = (storeId, createState) => {
38513
+ const store = createStore(createState);
38511
38514
  const stores = getIslandStores();
38512
- const existingStore = stores.get(storeId);
38513
- if (existingStore) {
38514
- return existingStore;
38515
- }
38516
- const store = createStore()((set, get, api) => createState((update) => {
38517
- set((state) => {
38518
- const nextPartial = typeof update === "function" ? update(state) : update;
38519
- return {
38520
- ...state,
38521
- ...nextPartial
38522
- };
38523
- });
38524
- }, get, api));
38515
+ const storeInstances = stores.get(storeId) ?? new Set;
38525
38516
  const initialSnapshot = getIslandStoreSnapshot()[storeId];
38526
38517
  applySnapshot(store, initialSnapshot);
38527
- getIslandStoreSnapshot()[storeId] = toSerializableState(store.getState());
38518
+ let isApplyingExternalSnapshot = false;
38519
+ const applyExternalSnapshot = (snapshot) => {
38520
+ isApplyingExternalSnapshot = true;
38521
+ applySnapshot(store, snapshot);
38522
+ };
38523
+ const syncSnapshot = (state) => {
38524
+ const nextSnapshot = toSerializableState(state);
38525
+ getIslandStoreSnapshot()[storeId] = nextSnapshot;
38526
+ for (const peerStore of storeInstances) {
38527
+ if (peerStore.store === store) {
38528
+ continue;
38529
+ }
38530
+ peerStore.applyExternalSnapshot(nextSnapshot);
38531
+ }
38532
+ };
38533
+ storeInstances.add({
38534
+ applyExternalSnapshot,
38535
+ store
38536
+ });
38537
+ stores.set(storeId, storeInstances);
38538
+ syncSnapshot(store.getState());
38528
38539
  store.subscribe((state) => {
38529
- getIslandStoreSnapshot()[storeId] = toSerializableState(state);
38540
+ if (isApplyingExternalSnapshot) {
38541
+ isApplyingExternalSnapshot = false;
38542
+ return;
38543
+ }
38544
+ syncSnapshot(state);
38530
38545
  });
38531
- stores.set(storeId, store);
38532
38546
  return store;
38533
38547
  };
38534
38548
  var readIslandStore = (store, selector) => selector(store.getState());
@@ -38575,5 +38589,5 @@ export {
38575
38589
  Island
38576
38590
  };
38577
38591
 
38578
- //# debugId=FA0D8CD2D75B6B1D64756E2164756E21
38592
+ //# debugId=02F3241D64B3EF6C64756E2164756E21
38579
38593
  //# sourceMappingURL=browser.js.map