-
Notifications
You must be signed in to change notification settings - Fork 18
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
Move responsibility of cleaning up effects from facets to useEffect()
/ useFacetEffect()
#96
Conversation
- Re-implement cleanup logic in useFacetEffect() - Create a factory for creating useFacetEffect() and useFacetLayoutEffect() - Exclude /dist folder when running unit tests
createFacet()
to useEffect()
/ useFacetEffect()
createFacet()
to useEffect()
/ useFacetEffect()
useEffect()
/ useFacetEffect()
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.
Freaking awesome that we get to simplify the createFacet
implementation.
This reverts commit 5b76def.
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.
Awaiting QA review before we can merge this.
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.
We have a go from QA!
Background
I had a scenario where a
useFacetEffect()
(effect) depended on a facet from auseFacetMap()
. I noticed that the clean up handler for the effect was sometimes called, but the effect itself wasn't called again with the new value(s). This introduced an issue to me since I was subscribing / unsubscribing to an event in the effect / clean up.Problem
After investigating the issue I noticed that this occurs because of how the facet itself is responsible of cleaning up listeners (effects).
useFacetMap()
is furthermore just a thin layer on top of the facet adding a selector and an equal check. If an effect is subscribing to theuseFacetMap()
facet and the underlying facet updates, but theuseFacetMap()
is not (because of its equality check), the effect's clean up function will run, but not the effect itself with new value(s).Solution
This PR removes the functionality of keeping track of clean up handlers in the facet itself. That logic is instead moved to
useFacetEffect()
/useFacetLayoutEffect()
. This accomplishes 2 things:As a bonus, this PR adds a factory function that creates the
useFacetEffect()
and theuseFacetLayoutEffect()
hooks.Full list of changes
createFacet.ts
useFacetEffect()
useFacetEffect()
anduseFacetLayoutEffect()
/dist
folder when running unit tests