-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add AbortSignal to OpenSRPServer service #625
Conversation
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.
@p-netm this is looking great, love how you're using the useEffect
return to abort the signal! Just a few requests below:
return () => { | ||
controller.abort(); | ||
}; |
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.
Might it be DRY'er to have a util function that does this instead of re-writing the anon function?
const controllerAborter = (controller) => { controller.abort() };
...
useEffect(() => {
...
return controllerAborter(controller);
}, []);
(but with a better name than controllerAborter
?)
9b467c8
to
af29459
Compare
the goal for abortFetch was to prevent the error of setStating on an unmounted component. Meaning we only truly need abortFetch in components whose async operations' callbacks have a setState call. For most other components the async operations dispatch the response to the store other than call a setState in the callback. i think we should retain the callback's functionality since in this case it will not cause the aforementioned error and also I believe we might want for resolved data to be added to store if even if we unmount a component.
Refactor container tests that assumed mandatory usage of Abortsignal
if (loading === true) { | ||
if (plan === null) { |
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.
why this change?
).catch(e => { | ||
throw e; | ||
}); | ||
).catch(err => err); |
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.
Do we want to use displayError
here?
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.
Naah!, this is part of the test, I want the error to actually fail the test.
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.
Why are we not using the official OpenSRP service package?
const allOpenMRSUsers = await loadOpenMRSUsers(); | ||
) | ||
.list() | ||
.catch((err: Error) => displayError(err)); |
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.
Do we want to add a test that displayError
is, in fact, called?
@@ -99,7 +98,7 @@ const IRSAssignmentPlansList = (props: PlanAssignmentsListProps) => { | |||
loadData().catch(error => displayError(error)); | |||
}, []); | |||
|
|||
if (loading) { | |||
if (plans.length < 1) { |
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.
If we get 0 plans from the API, does this mean we will show the loading indicator forever?
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 was thinking about this wrong. let me refactor.
} | ||
} | ||
|
||
useEffect(() => { | ||
loadData().catch(err => displayError(err)); | ||
}, []); | ||
|
||
if (loading === true) { | ||
if (plans.length < 1) { |
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.
If we get 0 plans from the API, does this mean we will show the loading indicator forever?
@p-netm can we add notes on how to proceed, and then possibly close this? |
Going to close this. |
closes #554, close #356
Add cleanup functions to Functional components that aborts fetch calls to opensrpreason : 16eba72