-
-
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
mobx.observe does not call callback when computed property changes #486
Comments
I never used |
I understand your point. I guess I just find it odd that |
That is why setting |
I have to agree with @fenduru, current behavior doesn't make sense. The I wonder why it works how it works, I hope it's not because of some technical limitation... EDIT: You might want to change the title, the dependency on external observable is not the cause of the problem. |
Hmm good point, I usually don't consider computeds as 'full members', they are not enumerable as well for example. But at least if the event is emitted the user is able to choose himself to ignore the change. I'll mark this for 3.0 candidate, as the change might be breaking for people. |
Tinkered about this a bit more, (already started to change it) but I think the current behavior is correct
|
Isn't that newly produced value stored/cached to "box" (like Maybe the
Btw, isn't |
@urugator yep good thoughts. I'm not entirely sure about this one either. I think for now the status quo is fine until the community has a stronger opinion about this :) So far there are good use cases for both solutions. And btw, yeah |
@mweststrate However, there is one thing I would definitely change and that is unifying the listener arguments. Its sometimes an event and sometimes prev/new value, I think it's confusing and impractical and even the documentation has trouble to make that clear:
(exception isn't just boxed observables, but also computed and props) and then:
|
I am trying to create an object that has a number of computed properties on it, and I would like to observe whenever any of the computed properties change using
mobx.observe(obj, callback)
. This works fine if I explicitly pass the propertyName argument, however not if I try to observe the parent object itself.I do see the docs mention that
observe(obj.name, callback)
is different thanobserve(obj, 'name', callback)
, but I believe this is different because I do not want to provide the name at all, and instead I want to listen for changes to any property on the parent object.I am expecting
mobx.observe(obj, callback)
to callcallback
more than or equal to the number of timesmobx.observe(obj, 'property', callback)
would callcallback
.Code
Console output
Expected output
jsFiddle
The text was updated successfully, but these errors were encountered: