Refactor useObservable to handle deeply nested values#4
Refactor useObservable to handle deeply nested values#4hrastnik wants to merge 4 commits intocoolsoftwaretyler:mainfrom
Conversation
hooks/useObservable.ts
Outdated
| useLayoutEffect(() => { | ||
| const disposer = reaction( | ||
| function expression() { | ||
| //// Uncomment this to see what paths are being accessed in the render |
There was a problem hiding this comment.
suggestion: let's change this to a logging function that we can configure with an optional argument to useObservable. Maybe just like useObservable<T extends IStateTreeNode>(model: T, debug?: boolean), and then if debug is true, we run these logs?
There was a problem hiding this comment.
I've got that locally, will push up tomorrow.
|
Thanks @hrastnik! This is awesome. I was able to confirm the getter with arguments ( There are quite a few TypeScript errors here, and we've lost the types coming back from |
|
Feel free to push to the branch. I won't have much time until the weekend to work on this. |
|
Will do! I'll make a few modifications here and let you know when I do so you can pull things down. Thanks again! |
|
Just quickly pushed up some of the code to demo the |
|
I'll try to push up a few more ideas tomorrow, although I'm about to do a cross country move, so I may be a little slow to respond until late next week. |
I rewrote the implementation to use recursion to track which properties have been accessed.
Then, in a useLayoutEffect it replays the property accesses it tracked during render in a reaction so it knows when to re-render