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

Cannot change results order/sort in reducer #1057

Closed
SachaG opened this issue Dec 18, 2016 · 8 comments
Closed

Cannot change results order/sort in reducer #1057

SachaG opened this issue Dec 18, 2016 · 8 comments

Comments

@SachaG
Copy link

SachaG commented Dec 18, 2016

When I re-sort a list of results in a query reducer (for example, the list could be organized alphabetically and one of the item names just changed), it doesn't seem like the new sort gets propagated through to the UI, or even to the store (although any modifications to documents within the list do get propagated correctly).

Has anybody else observed a similar issue? Or should I assume the problem is coming from my side of things?

@wmertens
Copy link
Contributor

You should always create new objects when you change props. E.g. return [...oldArray].sort(etc)

@SachaG
Copy link
Author

SachaG commented Dec 18, 2016

@wmertens oh that totally worked, thanks so much!

I still think it's worth asking if apollo-client should create new objects itself behind the scenes, to avoid that issue? Or else maybe just highlight it in the docs?

@helfer
Copy link
Contributor

helfer commented Dec 19, 2016

@SachaG we were thinking about using deep freeze in development mode to make sure objects aren't changed accidentally.

@wmertens
Copy link
Contributor

wmertens commented Dec 19, 2016 via email

@SachaG
Copy link
Author

SachaG commented Dec 19, 2016

I guess we need to weigh the performance cost vs the lost developer productivity if this turns out to be an issue people frequently run into. Personally I like a little magic :)

@helfer
Copy link
Contributor

helfer commented Dec 19, 2016

@wmertens I think it's a reasonable tradeoff to use it in development mode where performance isn't quite as important. The potential time savings of not having to track down accidental modifications are worth the limited overhead, especially considering that in production you don't have to pay that price.

@wmertens
Copy link
Contributor

wmertens commented Dec 19, 2016 via email

@helfer
Copy link
Contributor

helfer commented Dec 19, 2016

@SachaG Thanks for bringing it up! I think I'll close this issue since we're already tracking it on the roadmap.

@helfer helfer closed this as completed Dec 19, 2016
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants