@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.
@@ -30266,31 +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()((set, get, api) => createState((update) => {
30279
- set((state) => {
30280
- const nextPartial = typeof update === "function" ? update(state) : update;
30281
- return {
30282
- ...state,
30283
- ...nextPartial
30284
- };
30285
- });
30286
- }, get, api));
30277
+ const storeInstances = stores.get(storeId) ?? new Set;
30287
30278
  const initialSnapshot = getIslandStoreSnapshot()[storeId];
30288
30279
  applySnapshot(store, initialSnapshot);
30289
- 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());
30290
30301
  store.subscribe((state) => {
30291
- getIslandStoreSnapshot()[storeId] = toSerializableState(state);
30302
+ if (isApplyingExternalSnapshot) {
30303
+ isApplyingExternalSnapshot = false;
30304
+ return;
30305
+ }
30306
+ syncSnapshot(state);
30292
30307
  });
30293
- stores.set(storeId, store);
30294
30308
  return store;
30295
30309
  };
30296
30310
  var readIslandStore = (store, selector) => selector(store.getState());
@@ -30312,5 +30326,5 @@ export {
30312
30326
  createIslandStore
30313
30327
  };
30314
30328
 
30315
- //# debugId=677B248489EBBD7764756E2164756E21
30329
+ //# debugId=3BD49DBE8F59104B64756E2164756E21
30316
30330
  //# sourceMappingURL=server.js.map