ngrx / platform

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

feat(signals): replace `idKey` with `selectId` when defining custom entity ID #4396

Closed markostanimirovic closed 2 weeks ago

markostanimirovic commented 3 weeks ago

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

The custom entity id is defined using the idKey property:

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

Closes #4217, #4392

What is the new behavior?

The custom entity id is defined using the selectId function:

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

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

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

This is not considered as a breaking change because the @ngrx/signals package is in developer preview.

netlify[bot] commented 3 weeks ago

Deploy Preview for ngrx-io ready!

Name Link
Latest commit 02d058561b3bc695ded0de7c7a93d5b7216ea4d6
Latest deploy log https://app.netlify.com/sites/ngrx-io/deploys/667209fdfded320008e9a1a2
Deploy Preview https://deploy-preview-4396--ngrx-io.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.