-
-
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
How to track object mutations? #662
Comments
Check out my timer examples, https://github.com/mobxjs/mobx-examples . They On Nov 17, 2016 4:39 PM, "Tanguy Krotoff" notifications@github.com wrote:
|
@tkrotoff, do you mean documenting how mobx reacts? |
@mattruby In other words (tell if wrong), Mobx tracks the pointer value (pointer as in C/C++ pointer). That's why |
@tkrotoff Actually it's You can try this example and you'll find that mobx tries to make object content observable recursively: https://jsfiddle.net/nbk3peoa/ |
@mweststrate Maybe mobx can do some monkey patch stuff to make Date instance changes trackable? Just like what mobx did with Array instances. |
@tkrotoff What ended up being the elegant solution to this? Tearing my hair out a bit... |
I'm curious about that too because I have the same problem. Is there some more elegant solution? |
btw, will ES6 Proxy be able to solve this problem? |
@kpennell @francesco-carrella I recommend to treat the date as immutable, and every time you want to modify it, produce a new data and store that in a |
Thanks for the support @mweststrate, I ended using this way out. |
Replying to my question "will ES6 Proxy solve this problem?", the answer is no. See https://codepen.io/tkrotoff/pen/WyWOZP |
Example with Moment.js:
Output:
Online jsFiddle: https://jsfiddle.net/tkrotoff/ek64vvtf/
autorun
is not being called when runningperson.birthday.add(1, 'day')
.Moment.add mutates
birthday
and Mobx does not know about it.How can it be done elegantly?
PS: I've spent a long time in my code base before understanding why it did not work as I expected, I suggest to document this to avoid others the same mistake
The text was updated successfully, but these errors were encountered: