-
Notifications
You must be signed in to change notification settings - Fork 987
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
Refs #29992 - pass stopInterval as callback also on API success #7842
Refs #29992 - pass stopInterval as callback also on API success #7842
Conversation
Issues: #29992 |
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.
Thanks @LaViro! 👍
I left a few inline comments :)
@@ -131,3 +131,6 @@ dispatch( | |||
``` | |||
|
|||
The success handling function will receive the response object from the API request. | |||
|
|||
In case you are also using the interval middleware with the same `KEY`, |
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.
can you also add a mention in the Interval Middleware story?
@@ -36,6 +36,21 @@ Array [ | |||
`; | |||
|
|||
exports[`API get should dispatch request and success actions on resolve 1`] = ` | |||
Array [ |
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.
what this extra snap gives us?
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 captures the handleSuccess
callback args as the API response
,
and the second arg is a Function
- the stopInterval
/ warning callbacks
@@ -22,6 +22,10 @@ export const apiRequest = async ( | |||
) => { | |||
const { REQUEST, SUCCESS, FAILURE } = actionTypeGenerator(key, actionTypes); | |||
const modifiedPayload = { ...payload, url }; | |||
const stopIntervalCallback = selectDoesIntervalExist(getState(), key) | |||
? () => dispatch(stopInterval(key)) | |||
: noop; |
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.
how about making a function that prints to the console a warning if a user consumes it?
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.
great idea, added :)
7e0d456
to
f181bb8
Compare
@@ -25,6 +26,9 @@ export const apiRequest = async ( | |||
) => { | |||
const { REQUEST, SUCCESS, FAILURE } = actionTypeGenerator(key, actionTypes); | |||
const modifiedPayload = { ...payload, url }; | |||
const stopIntervalCallback = selectDoesIntervalExist(getState(), key) | |||
? () => dispatch(stopInterval(key)) | |||
: () => console.warn(`There's no interval API request for the key: ${key}`); |
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 this warning needed in production?
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 I think so, it will be easier for debugging
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.
Thanks, @LaViro 👍
We do have console warnings in other places that trigger in production, though the deprecate
function triggers only in development which makes sense.
Katello failures aren't related
There are many scenarios where we would like to stop the API interval after receiving some information from the server,
in order to do it easily, the
stopInterval
for the specific key would be passed as a second param in thehandleSuccess
callback.