@angular-architects/ngrx-toolkit 20.4.0 → 20.4.1

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.
@@ -342,7 +342,7 @@ Enable automatic indexing via withDevTools('${storeName}', { indexNames: true })
342
342
  }, {});
343
343
  this.#currentState = Object.entries(this.#currentState).reduce((newState, [storeName, state]) => {
344
344
  if (storeName !== name) {
345
- newState[name] = state;
345
+ newState[storeName] = state;
346
346
  }
347
347
  return newState;
348
348
  }, {});
@@ -350,18 +350,31 @@ Enable automatic indexing via withDevTools('${storeName}', { indexNames: true })
350
350
  tracker.removeStore(id);
351
351
  }
352
352
  }
353
- renameStore(oldName, newName) {
354
- const storeNames = Object.values(this.#stores).map((store) => store.name);
355
- const id = throwIfNull(Object.keys(this.#stores).find((id) => this.#stores[id].name === oldName));
356
- if (storeNames.includes(newName)) {
353
+ /**
354
+ * Renames a store identified by its internal id. If the store has already
355
+ * been removed (e.g. due to component destruction), this is a no-op.
356
+ */
357
+ renameStore(id, newName) {
358
+ const storeEntry = this.#stores[id];
359
+ if (!storeEntry) {
360
+ return;
361
+ }
362
+ const oldName = storeEntry.name;
363
+ if (oldName === newName) {
364
+ return;
365
+ }
366
+ const otherStoreNames = Object.entries(this.#stores)
367
+ .filter(([entryId]) => entryId !== id)
368
+ .map(([, s]) => s.name);
369
+ if (otherStoreNames.includes(newName)) {
357
370
  throw new Error(`NgRx Toolkit/DevTools: cannot rename from ${oldName} to ${newName}. ${newName} is already assigned to another SignalStore instance.`);
358
371
  }
359
- this.#stores = Object.entries(this.#stores).reduce((newStore, [id, value]) => {
360
- if (value.name === oldName) {
361
- newStore[id] = { ...value, name: newName };
372
+ this.#stores = Object.entries(this.#stores).reduce((newStore, [entryId, value]) => {
373
+ if (entryId === id) {
374
+ newStore[entryId] = { ...value, name: newName };
362
375
  }
363
376
  else {
364
- newStore[id] = value;
377
+ newStore[entryId] = value;
365
378
  }
366
379
  return newStore;
367
380
  }, {});
@@ -406,7 +419,7 @@ function withDevtools(name, ...features) {
406
419
  // TODO: use withProps and symbols
407
420
  return {
408
421
  [renameDevtoolsMethodName]: (newName) => {
409
- syncer.renameStore(name, newName);
422
+ syncer.renameStore(id, newName);
410
423
  },
411
424
  [uniqueDevtoolsId]: () => id,
412
425
  };