-
Notifications
You must be signed in to change notification settings - Fork 3
chore: Internal reactive store utils #145
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
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #145 +/- ##
==========================================
+ Coverage 99.38% 99.41% +0.02%
==========================================
Files 33 34 +1
Lines 810 850 +40
Branches 214 229 +15
==========================================
+ Hits 805 845 +40
Misses 5 5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
useEffect( | ||
() => { | ||
if (prevStore.current !== store) { | ||
effect(selector(store.get()), selector(prevStore.current.get())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here the effect runs if the store changed, even if the actual state hasn't changed. Either this should not happen (my preference) or the function's documentation should be updated to inform users of this hook about this.
// Ignoring selector and effect as they are expected to stay constant. | ||
// eslint-disable-next-line react-hooks/exhaustive-deps |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should either be documented for users of the hook, or adjusted so that they do not have to stay constant. This could likely be achieved by using the useStableCallback
function. The same applies to the useSelector
hook below
|
||
// We create subscription synchronously during the first render cycle to ensure the store updates that | ||
// happen after the first render but before the first effect are not lost. | ||
const unsubscribeRef = useRef(store.subscribe(selector, newState => setState(selector(newState)))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will create a new subscription on every render, which will likely be bad for performance over time
Rel: [GNQwANHlIGi6]
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.