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
Update mobx computed value error #25
Comments
Conceptually, one should usually not need to serialize computed values. Since it is derived data there is often no need to store it. But if you want to serialize it, giving it a @serializable @computed get prop() {
return expr
}
set prop(v) {
// ignore updates during de-serialization
} |
Then the problem becomes:
http://codepen.io/fusepilot/pen/eBvMMK
Right, but it is useful when you just want to flush the entire state including computed values to json and not have to duplicate the computed function in the code receiving it. |
What mobx version are you using? I think setters for computed properties were only introduced in 2.6 or later |
Yeah, the codepen I was using for the reproductions was using 2.0.0. Updated to 2.6.3 and it works. Thanks! |
Reproduction: http://codepen.io/fusepilot/pen/mOOgWX
When deserializing back to a mobx computed value using
deserializeState()
in example 7, I get this error:Invariant failed: [ComputedValue 'Box@1870.area'] It is not possible to assign a new value to a computed value.
I was expecting
update
to ignore setting computed values. But maybe that requires serializr to have too much knowledge of mobx's inner workings. Not sure.Is this a bug? Or is there a proper way to avoid this problem when updating?
The text was updated successfully, but these errors were encountered: