valtio-observe: observe and useObserve #1069
artelk
started this conversation in
Show and tell
Replies: 1 comment
-
Added |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi guys. I created a library valtio-observe with two functions: observe and useObserve.
The observe works about like watch from valtio-reactive but it is implemented differently.
I implemented a property-level subscription logic (the notification aren't propagated to parent objects).
The observe excecutes the func and passes its result to the consume function.
It subscribes to all proxy properties which getters were accessed while calling the func.
Additianally it searches for proxies in the returned value and subscribes to them.
The observe returns a function that should be called to stop the process.
Note: If the reference to the stop function is lost the obrerving will be stoped on the next GC run.
Test
Vanilla js example
useObserve with React
Beta Was this translation helpful? Give feedback.
All reactions