RFC: Provide option for strict immutability of selectors's output #3086
Replies: 4 comments 3 replies
-
Putting this on my radar to possibly work on |
Beta Was this translation helpful? Give feedback.
-
If you give me some guidance and green light I'm willing to try and submit a PR |
Beta Was this translation helpful? Give feedback.
-
Thanks @samuelfernandez and @david-shortman. We will give some guidance. Don't start on any work on this just yet |
Beta Was this translation helpful? Give feedback.
-
Should return values be immutable as a best practice? Specifically talking about derived values that are transformed from store state that is already in the reducer. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
It is great that the store returns an immutable JS object, which helps in finding bugs in case the state was modified outside of the reducer by mistake. Lately, this has become a core part of the framework, including actions, which is nice.
However, we also have selectors. I have faced the problem of mistakenly modifying an object coming from a selector, which caused undesirable side-effects.
It might be nice that the results of
createSelector
were made immutable at the output to make sure they are not modified, since eventually a selector is an extension of the store's data. This could be a breaking change for some apps, so maybe it could just be an opt-in option in the root settings, or an option at eachcreateSelector
Describe any alternatives/workarounds you're currently using
Be a good programmer and avoid going evil
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
Beta Was this translation helpful? Give feedback.
All reactions