-
-
Notifications
You must be signed in to change notification settings - Fork 15.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
Freeze the state tree in dev? #135
Comments
Is there a way maybe to validate that and log a warning? Using |
We could use something like https://github.com/substack/deep-freeze |
Sounds like a good idea. |
Let's try it then 👍 |
👍 |
If somebody wants to test this in a branch please do. |
I think it would be better to do what @emmenko suggests. We could deep clone the state after each dispatch and before dispatching we can check if the state is deeply equal to that previously cloned state, and if not, throw a warning, or an error directly. We can also verify that the new state returned by each dispatch is a brand new object. Since it's only for dev it shouldn't matter that much with regards to performance. In any case, we can provide a way to disable that check. |
Yeah, we could do that too. Would such cloning still work with ImmutableJS? |
We can make it work with Immutable, I don't think any out of the box cloning library works with it though. |
Perhaps we could bail out if we see Immutable (since it already guarantees immutability). Not sure. |
If noone is already working on this I'm willing to give it a try |
Late to the party but this is a good idea to catch subtle bugs and late-night coding session issues. |
How about we only do this if the state is a plain object? If it's anything else (e.g. Immutable.js) we trust the user knows what they're doing. |
Yes, we can try like this and see how it goes. |
Let's continue the discussion in #138. |
Should we deep-
Object.freeze
the state tree in development? I don't know how much of a perf hit that is.It's hard for people to write mutation-free code from the first try so we might as well help them.
The text was updated successfully, but these errors were encountered: