-
Notifications
You must be signed in to change notification settings - Fork 179
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
feat: perf event handlers #553
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
throw parsedError.status | ||
} | ||
} | ||
throw queryError |
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.
is there a way to indicate in perf.ts
that these can throw certain types of errors? should the integrator be aware so they can handle them?
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.
Yes, we could extend Promise to have a typed catch
method: https://github.com/reduxjs/redux-toolkit/blob/ad508a18d3a475fafecfaa77cf2c50da755c7e3e/packages/toolkit/src/query/core/buildMiddleware/types.ts#L99
However, this would not maintain the typing with async-await usage, so I don't think it's worth the added effort (and I don't know that we'd get typechecking without avoiding async-await).
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.
I think a good follow up would be for us to export an enum (or extend Error
) and only throw these errors from integration hooks, but I don't think that that should be a part of this PR. It could be a future improvement.
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.
sounds good - i was imagining some generic "throws" descriptor on the function , not even typing it. maybe something worth calling out in the docs if we update them for the PerfEventHandlers
src/hooks/swap/useWrapCallback.tsx
Outdated
} | ||
}, [parsedAmountIn, wrappedNativeCurrencyContract, wrapType]) | ||
const callback = usePerfEventHandler('onWrapSend', wrapCallback, parsedAmountIn && { amount: parsedAmountIn }) |
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.
{ amount: parsedAmountIn }
is inputs to wrapCallback
right? kinda hard to tell without comments in usePerfEventHandler
and without labelling these inputs
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.
refactored to (hopefully) make this more clear. usePerfEventHandler
is meant to mirror the arguments of the perf event handler, so I want it to be ordinal inputs (ie not an options object).
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 makes sense now thanks
throw parsedError.status | ||
} | ||
} | ||
throw queryError |
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.
sounds good - i was imagining some generic "throws" descriptor on the function , not even typing it. maybe something worth calling out in the docs if we update them for the PerfEventHandlers
🎉 This PR is included in version 2.48.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Adds new perf event handlers so that relevant events can be instrumented by integrators (eg to track performance metrics):
onSwapQuote
onTokenAllowance
onPermit2Allowance
onSwapSend
onWrapSend
Deprecates existing handlers whose functionality is shared by the new handlers:
onSwapApprove
,onSubmitSwapClick
.Perf event handlers should record the entire event, so they all follow a similar pattern and use a new helper hook:
usePerfEventHandler
. All perf event hooks take two parameters:args
and anevent
. Theevent
is a promise that resolves (or rejects) when the instrumented event has completed.usePerfEventHandler
wrapsevent
in a resolved Promise, so that it is not executed until after the perf event handler has executed. This allows integrators to instrument the full event (eg even if it triggers a fetch).INFRA-144