-
-
Notifications
You must be signed in to change notification settings - Fork 265
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
valtio should avoid state change for compare equal value #511
Comments
It should skip setting if it's the same as the previous one. (Compared with For example, this should work as expected. const state = proxy({ obj: {} })
state.obj = state.obj But, this doesn't,
because it's a new object. This should be the default behavior that we shouldn't change. |
state.ref = ref(0) I don't feel like writing like this, but it should just mean |
Thanks, I expected immer like mutation detect, seems I was wrong, but do hope valtio support custom change compare, valtio already batched mutation.
Just use 0 as a reference, due to #510 , the |
I expect it work fine with state.ref = ref(document.body)
state.ref = ref(document.body) // should be no-op |
btw, we could create a proxy object in advance. const obj = proxy({ foo: 1 }) // initialize object outside
const state = proxy({ obj })
state.obj = obj // should be no-op |
As I wrote in a different issue/discussion, valtio is designed like an opposite of immer.
We do want to avoid adding features in valtio. It's one of the ground rules from the start. Line 155 in 7c85c14
But this feature is not very developer friendly. It's basically for 3rd-party library developers. It means you should be able to create proxyWithCustomComparator util.
|
Thanks, I will look into it. |
Wow, after
valtio works like expected, thanks. https://codesandbox.io/s/valtio-render-test-lzqhf7 Can close the issue now. |
@dai-shi thanks, will watch the release |
new to valtio, I expected mutate state is like immer with proxy, if assign the same value, the state should not change, but seems not the case.
like
Is it possible to pass the custom comparator or use with immer to prevent the change ?
The text was updated successfully, but these errors were encountered: