Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello again 👋 This PR addresses #7. I like this approach quite a bit more than my earlier approach as it's isolated to the listener implementation. With this change, I use an atom along with
interop/next-tick
to ensure that all "ui" listeners (from the use-sub hook) are triggered after values have updated (both Sub and DynamicSub updates).The listeners are fired in the order that they are registered (which is why I changed the key for
use-sub
). This is important because components higher in the tree (registered earlier) should have their hooks updated before further down components. An example of why this is needed is if you had a router subscribe to the current route, you'd want to make sure it's updated before downstream components are (otherwise downstream components could render, when they shouldn't, and have invalid hooks fired right before unmounting).I've added these changes to my own refx project and it's been working great for the past week (I'm seeing improved performance when using our app 🎉).
Let me know if you'd like any changes or have any feedback!