cogsbox-state 0.5.434 → 0.5.435

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.
package/src/store.ts CHANGED
@@ -279,16 +279,20 @@ export const getGlobalStore = create<CogsGlobalState>((set, get) => ({
279
279
  const newShadowStore = new Map(get().shadowStateStore);
280
280
  let changed = false;
281
281
 
282
- // This function marks a single path as dirty if it was previously synced.
283
282
  const setDirty = (currentPath: string[]) => {
284
283
  const fullKey = [key, ...currentPath].join('.');
285
284
  const meta = newShadowStore.get(fullKey);
286
285
 
287
- // We only mark something as dirty if it was previously synced from the server.
288
- // We also check `isDirty !== true` to avoid redundant updates.
289
- if (meta && meta.stateSource === 'server' && meta.isDirty !== true) {
286
+ // We mark something as dirty if it isn't already.
287
+ // The original data source doesn't matter.
288
+ if (meta && meta.isDirty !== true) {
290
289
  newShadowStore.set(fullKey, { ...meta, isDirty: true });
291
290
  changed = true;
291
+ } else if (!meta) {
292
+ // If there's no metadata, create it and mark it as dirty.
293
+ // This handles newly created fields within an object.
294
+ newShadowStore.set(fullKey, { isDirty: true });
295
+ changed = true;
292
296
  }
293
297
  };
294
298
 
@@ -304,7 +308,6 @@ export const getGlobalStore = create<CogsGlobalState>((set, get) => ({
304
308
  }
305
309
  }
306
310
 
307
- // Only update the global state if something actually changed.
308
311
  if (changed) {
309
312
  set({ shadowStateStore: newShadowStore });
310
313
  }
@@ -648,6 +651,12 @@ export const getGlobalStore = create<CogsGlobalState>((set, get) => ({
648
651
  clearSelectedIndex: ({ arrayKey }: { arrayKey: string }): void => {
649
652
  set((state) => {
650
653
  const newMap = state.selectedIndicesMap;
654
+ const acutalKey = newMap.get(arrayKey);
655
+ if (acutalKey) {
656
+ get().notifyPathSubscribers(acutalKey, {
657
+ type: 'CLEAR_SELECTION',
658
+ });
659
+ }
651
660
 
652
661
  newMap.delete(arrayKey);
653
662
  get().notifyPathSubscribers(arrayKey, {