@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.
@@ -30266,23 +30266,45 @@ var initializeIslandStores = (state) => {
30266
30266
  };
30267
30267
  globalThis.__ABS_ISLAND_STATE__ = nextSnapshot;
30268
30268
  for (const [storeId, store] of getIslandStores()) {
30269
- applySnapshot(store, nextSnapshot[storeId]);
30269
+ for (const instance of store) {
30270
+ instance.applyExternalSnapshot(nextSnapshot[storeId] ?? {});
30271
+ }
30270
30272
  }
30271
30273
  };
30272
- var createIslandStore = (storeId) => (createState) => {
30274
+ var createIslandStore = (storeId, createState) => {
30275
+ const store = createStore(createState);
30273
30276
  const stores = getIslandStores();
30274
- const existingStore = stores.get(storeId);
30275
- if (existingStore) {
30276
- return existingStore;
30277
- }
30278
- const store = createStore()(createState);
30277
+ const storeInstances = stores.get(storeId) ?? new Set;
30279
30278
  const initialSnapshot = getIslandStoreSnapshot()[storeId];
30280
30279
  applySnapshot(store, initialSnapshot);
30281
- getIslandStoreSnapshot()[storeId] = toSerializableState(store.getState());
30280
+ let isApplyingExternalSnapshot = false;
30281
+ const applyExternalSnapshot = (snapshot) => {
30282
+ isApplyingExternalSnapshot = true;
30283
+ applySnapshot(store, snapshot);
30284
+ };
30285
+ const syncSnapshot = (state) => {
30286
+ const nextSnapshot = toSerializableState(state);
30287
+ getIslandStoreSnapshot()[storeId] = nextSnapshot;
30288
+ for (const peerStore of storeInstances) {
30289
+ if (peerStore.store === store) {
30290
+ continue;
30291
+ }
30292
+ peerStore.applyExternalSnapshot(nextSnapshot);
30293
+ }
30294
+ };
30295
+ storeInstances.add({
30296
+ applyExternalSnapshot,
30297
+ store
30298
+ });
30299
+ stores.set(storeId, storeInstances);
30300
+ syncSnapshot(store.getState());
30282
30301
  store.subscribe((state) => {
30283
- getIslandStoreSnapshot()[storeId] = toSerializableState(state);
30302
+ if (isApplyingExternalSnapshot) {
30303
+ isApplyingExternalSnapshot = false;
30304
+ return;
30305
+ }
30306
+ syncSnapshot(state);
30284
30307
  });
30285
- stores.set(storeId, store);
30286
30308
  return store;
30287
30309
  };
30288
30310
  var readIslandStore = (store, selector) => selector(store.getState());
@@ -30304,5 +30326,5 @@ export {
30304
30326
  createIslandStore
30305
30327
  };
30306
30328
 
30307
- //# debugId=EF4E4C1B4B9CC29864756E2164756E21
30329
+ //# debugId=3BD49DBE8F59104B64756E2164756E21
30308
30330
  //# sourceMappingURL=server.js.map