ngrx / platform

Reactive State for Angular
https://ngrx.io
Other
8.01k stars 1.97k forks source link

`@ngrx/signals/entity`: Replace `idKey` with `selectId` #4392

Closed markostanimirovic closed 3 months ago

markostanimirovic commented 3 months ago

Which @ngrx/* package(s) are relevant/related to the feature request?

signals

Information

To allow defining entity identifier from multiple properties, but also for consistency with @ngrx/entity, idKey will be replaced with selectId.

Before:

const TodosStore = signalStore(
  withEntities<Todo>(),
  withMethods((store) => ({
    addTodo(todo: Todo): void {
      patchState(store, addEntity(todo, { idKey: '_id' }));
    },
  })
);

After:

const selectId = (todo: Todo) => todo._id;

const TodosStore = signalStore(
  withEntities<Todo>(),
  withMethods((store) => ({
    addTodo(todo: Todo): void {
      patchState(store, addEntity(todo, { selectId }));
    },
  })
);

Describe any alternatives/workarounds you're currently using

No response

I would be willing to submit a PR to fix this issue