-
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
Describing and handling sharedFacet errors #125
Conversation
…mplemented it in the shared facet ecosystem And added a way of defining handling on errors by the user in sharedFacetDriver
…nd and we added it as an example in our tests
…d instead of the context error handler and checking that the context one is used when no local one exists
@@ -8,22 +8,24 @@ export function mapFacetsLightweight<M>( | |||
facets: Facet<unknown>[], | |||
fn: (...value: unknown[]) => M | NoValue, | |||
equalityCheck?: EqualityCheck<M>, | |||
onCleanup?: () => void, |
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.
It looks like this was added at one point, but its no longer needed?
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.
Because of this needed change to cleanup the new cache for SharedFacets in useSharedSelector
I had to change alll functions similar to mapFacetsCached
to include an optional onCleanup callback function to allow the cleaning up the cache when the facets are no longer there.
A new facet API might be introduced soon which will render this PR obselete, consider taking up the effort again after such change is done |
This PR adds a way to define errors for
SharedFacet
s in theSharedFacetDriver
using the onError callback like soThe sharedFacetDriver defines an error case, which calls an onError handler which should be set by either a specific
useSharedFacet()
instance or one of the new<SharedFacetsErrorBoundary />
instances which should catch any errors in any facet within it's scope and handle the error with the error handler you pass to itExample usage of a local facet error handler
Example of the usage of a
<SharedFacetsErrorBoundary />
The error you get passed to your callback from the sharedFacetDriver is of type
SharedFacetError
and it's basic type looks like soAnd the the end user can re-define what the error type should look like using the declaration merging typescript feature, we went with this implementation to make sure the end user gets typesafety in their error handling which they can re-define to suit their needs.
The end result of the type in the user's codebase would look something like this.