@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.
@@ -38504,23 +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()(createState);
38515
+ const storeInstances = stores.get(storeId) ?? new Set;
38517
38516
  const initialSnapshot = getIslandStoreSnapshot()[storeId];
38518
38517
  applySnapshot(store, initialSnapshot);
38519
- 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());
38520
38539
  store.subscribe((state) => {
38521
- getIslandStoreSnapshot()[storeId] = toSerializableState(state);
38540
+ if (isApplyingExternalSnapshot) {
38541
+ isApplyingExternalSnapshot = false;
38542
+ return;
38543
+ }
38544
+ syncSnapshot(state);
38522
38545
  });
38523
- stores.set(storeId, store);
38524
38546
  return store;
38525
38547
  };
38526
38548
  var readIslandStore = (store, selector) => selector(store.getState());
@@ -38567,5 +38589,5 @@ export {
38567
38589
  Island
38568
38590
  };
38569
38591
 
38570
- //# debugId=D9FEFCEEF55F5AEA64756E2164756E21
38592
+ //# debugId=02F3241D64B3EF6C64756E2164756E21
38571
38593
  //# sourceMappingURL=browser.js.map