-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
assigning plain object to observable property forces plain object to become observable #644
Comments
this is the intended default, but you can use modifiers to change this Op za 5 nov. 2016 11:29 schreef AlgoTrader [email protected]:
|
for I spend a couple of hours debugging why my original data was broken. It is first time that I see the setter to modify both the property and value to be assigned. |
I agree this can be confusing. The reasoning though is as follow; if your state is minimally defined, state should only be part of the observables and not be lingering around elsewhere, and hence the automatic conversion is very practical / boilerplate free. It makes sure complex data structures like :
can be observed by default in their entirety. Two alternatives are:
That being said the current approach isn't elegant either. When MobX switches to proxies, things will be slightly better, but still have assignments with side effects on the right-hand side. If somebody has a solution that is both sound and intuitive I am always glad to hear suggestions :) |
I agree with both your and my reasons. I would suggest to somehow warn of operations that have side effects. I got my pain of 'immutable' data to be muted. |
Maybe actually will fix @AlgoTrader :) Feel free to chime in on the related / follow-up discussion in #649 |
The code that represents the problem:
this.city = myCity;
I have to clone right side of assignments to prevent 'readonly' objects to be converted into observable.
I certainly want my plain objects to stay plain when they are in the right side of assignment! Assignment should modify left side, not the right one.
The text was updated successfully, but these errors were encountered: