Skip to content
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

@ngrx/entity add setOne (replaceOne?) method #2369

Closed
dmytro-gokun opened this issue Feb 11, 2020 · 8 comments · Fixed by #2410
Closed

@ngrx/entity add setOne (replaceOne?) method #2369

dmytro-gokun opened this issue Feb 11, 2020 · 8 comments · Fixed by #2410

Comments

@dmytro-gokun
Copy link
Contributor

Currently, the only way to replace an item is by using upsertOne. That does not work well with 'undefined' though (which is the case when the backend omits nulls when serializing to JSON). For example, i have an entity in the collection: {id: 1, name: 'foo', note: 'lorem ipsum'}. I want to replace it with {id: 1, name: 'foo'}. Obviously, upsertOne does not do the job well. Since the object is already there, it attempts to perform an update, thus treating the new object as a patch and leaving 'note' value unchanged. So, a new method 'setOne' is needed here.

Describe any alternatives/workarounds you're currently using

removeOne/addOne does the trick, but is not very efficient.

If accepted, I would be willing to submit a PR for this feature

[X ] Yes (Assistance is provided if you need help submitting a pull request)
[ ] No

@AdditionAddict
Copy link
Contributor

AdditionAddict commented Feb 11, 2020

Note upsertOne treats the passed entity as an update as does @ngrx/entity. In fact, previous interface was that the payload was an Update<T>. I'd say how upsertOne is behaving is intended behaviour which has been assessed in previous issues - #1604 (closed) #2061 (open)

I think upsertOne should have Partial <T> though.

Also every dictionary definition I've found has upsert means insert or update.
I think replaceOne is closer to the equivalent database term though I'd still vote for setOne if approved

@dmytro-gokun
Copy link
Contributor Author

@AdditionAddict I do not think there is any issue with upsertOne. It behaves in accordance with ngrx's update semantic. All is well here. It's just that it does not cover all possible scenarios. That's why i think setOne is needed.

As to name, i chose setOne to follow the pattern which is already here after a recent rename of addAll to setAll: #2347

@AdditionAddict
Copy link
Contributor

@dmytro-gokun I agree

@dmytro-gokun dmytro-gokun changed the title @ngrx/entity, add setOne (replaceOne?) method @ngrx/entity add setOne (replaceOne?) method Feb 13, 2020
@timdeschryver
Copy link
Member

I think adding a setOne makes sense, now that we have setAll.
Also, this is an issue that comes up regurarly (as pointed out)

@dmytro-gokun
Copy link
Contributor Author

@timdeschryver Great, i'll work on a PR

@timdeschryver
Copy link
Member

@dmytro-gokun can you hold it off for a bit?
I want to hear @brandonroberts 's thought about this first.

@dmytro-gokun
Copy link
Contributor Author

@timdeschryver sure

@brandonroberts
Copy link
Member

Sounds good to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants