-
-
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
UpsertOne does not clear missing optional fields #1604
Comments
At first, I was thinking that this isn't a bug. But after giving it some thought I do agree because it has the
Indeed, the two objects are being merged - ./modules/entity/src/unsorted_state_adapter.ts#L100 To clear it you will have to assign it to for example an empty string, |
Its not a bug, but I think it is a preference. To me an |
Those were my initial thoughts 😄 I think we can close this issue? |
Yep |
I see what you're saying and I agree it's a matter of preference. To me, intuitively, an |
@tkglaser The generally accepted term for upsert is to insert a new entry if none exists, update the entry if it does. |
@antonyRoberts I know. It's the signature of the function that threw me. As Tim pointed out above, it takes a |
@brandonroberts Can this be explicitly documented? It's rather unexpected behaviour, especially given that the signature does nothing to imply it will merge the provided objects with existing state. |
FYI, for anyone looking for solution, you can explicitly set the fields with |
Minimal reproduction of the bug/regression with instructions:
https://stackblitz.com/edit/ngrx-seed-eichyx
Press the buttons in the order of WITHOUT OPTIONAL -> WITH OPTIONAL -> WITHOUT OPTIONAL. Notice, that once the optional field is set, it is never unset.
Expected behavior:
I would expect that upsertOne() replaces the object in the store with the object I've passed in. Instead it seems to merge the two together. This way when an optional field is missing in the update, that field stays in the store forever. I find this counter intuitive.
Versions of NgRx, Angular, Node, affected browser(s) and operating system(s):
ngrx 6.4, NG 7, Node 10, Chrome, WIndows 10
Other information:
I would be willing to submit a PR to fix this issue
[X] Yes (Assistance is provided if you need help submitting a pull request)
[ ] No
The text was updated successfully, but these errors were encountered: