-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(signals): allow modifying entity id on update #4404
Conversation
✅ Deploy Preview for ngrx-io canceled.
|
c0e935c
to
2e89ae7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the current implementation, the ids can get out of sync with the entity keys. This happens when we update an entity with an existing id.
Is this expected? If so, I think adding a warning can be useful.
it('updates entity ids', () => {
const Store = signalStore(withEntities<User>());
const store = new Store();
patchState(
store,
addEntities([user1, user2]),
updateEntities({
ids: [user1.id],
changes: ({ id }) => ({ id: user2.id, firstName: `Updated Jimmy` }),
}),
);
// 👇 only has user 2
expect(store.entityMap()).toEqual({
[user2.id]: { ...user1, id: user2.id, firstName: 'Updated Jimmy' },
});
// 👇 user id 2 is added twice
expect(store.ids()).toEqual([user2.id, user2.id]);
});
@timdeschryver With allowing ID changes there are several ways to break/move entity collection to the inconsistent state. That's the reason why I was against this change initially. Users now have better control, but also responsibility. Let's check how I agree that warning will be useful 👍 |
I just checked |
190cfa8
to
149ceb5
Compare
2765dee
to
4082ea5
Compare
4082ea5
to
9990abd
Compare
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
It's not possible to modify entity ID via
update*
functions. Instead, it's necessary to remove the existing one and add a new entity with an updated ID:Closes #4235
What is the new behavior?
The
update*
updaters can be used to modify entity ID:Does this PR introduce a breaking change?
Other information
After this change, it's necessary to provide
selectId
to allupdate*
updaters if an entity has a custom ID.This is not considered as a breaking change because the
@ngrx/signals
package is in developer preview.