-
Notifications
You must be signed in to change notification settings - Fork 94
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
Deeply observe object #32
Comments
you can |
Source:
Complete output:
|
Proxies are created on demand, so the above code would never work, since no proxies are created for foo, bar and baz. To do so, the library should have to walk the entirely tree and create a proxy for every object on it on registering the observable. If you need that functionality, you can implement that yourself by doing exactly that: recursively walk the tree and observing every property. |
Ok, just for background this was in the context of react-easy-state, using a third party widget that takes a tree of data, i needed the widget to update whenever any element of the tree updates. I ended up using a different means for this case. It does seem like observing an entire tree is out of scope for react-easy-state. Thanks. |
Hey, this should work, I will check it in a sec. |
Sooo, this lib (and easy state) intercepts everything that 'can be intercepted'. Built-in functions in JS are sometimes implemented in none JS code (C++ for example). The above You can try this code for example and it will work.
Anyway, people rarely want to observe built-in functions, they usually observe 'normal JS code', which works all the time. I hope this helps. (Could you include a small repro of your easy-state issue?) |
Your problem with easy-state was probably something very different. I see you were passing a tree of data to a third party component and expected it to re-render when the data tree was mutated. In this case the issue was that the third part component was not a Your component was not using the data (it was not accessing parts of it), it just passed it on to the third party component. That component used the data, but it was not a This seems the be a pretty common use case, I will try to think about a good alternative for it by tomorrow. |
Wait, nested objects aren't made observable? Why not? |
From react-easy-state docs: |
How did you come to this conclusion? Nested objects are made observable on demand. |
Is there an example how to observe every property in nested object? |
BTW, some examples in this repo's README is wrong. observe(() => console.log(person), { scheduler: ... }); That log only observes observe(() => console.log(JSON.stringify(person)), { scheduler: ... }); Or some kind of explicit access of |
I would like to be able to observe for any change in a deep object.
The text was updated successfully, but these errors were encountered: