Commit 5412b8aa authored by Scott Hampton's avatar Scott Hampton

Stop polling after complete

We need to stop polling after we have
received the final report since the report
is not going to change anymore.

We should also stop polling after we
receive an error, so we're not constantly
polling an 500 request.
parent 45a41ff4
......@@ -54,7 +54,7 @@ export const fetchReport = ({ state, dispatch, commit }) => {
}
Visibility.change(() => {
if (!Visibility.hidden()) {
if (!Visibility.hidden() && state.isLoading) {
dispatch('restartPolling');
} else {
dispatch('stopPolling');
......@@ -62,14 +62,17 @@ export const fetchReport = ({ state, dispatch, commit }) => {
});
};
export const receiveReportSuccess = ({ commit }, { status, data }) => {
export const receiveReportSuccess = ({ commit, dispatch }, { status, data }) => {
if (status === httpStatusCodes.OK) {
commit(types.RECEIVE_REPORT_SUCCESS, data);
// Stop polling since we have the information already parsed and it won't be changing
dispatch('stopPolling');
}
};
export const receiveReportError = ({ commit }) => {
export const receiveReportError = ({ commit, dispatch }) => {
commit(types.RECEIVE_REPORT_ERROR);
dispatch('stopPolling');
};
// prevent babel-plugin-rewire from generating an invalid default during karma tests
......
......@@ -89,7 +89,7 @@ describe('Accessibility Reports actions', () => {
{ status: 200, data: mockReport },
localState,
[{ type: types.RECEIVE_REPORT_SUCCESS, payload: mockReport }],
[],
[{ type: 'stopPolling' }],
done,
);
});
......@@ -113,7 +113,7 @@ describe('Accessibility Reports actions', () => {
null,
localState,
[{ type: types.RECEIVE_REPORT_ERROR }],
[],
[{ type: 'stopPolling' }],
done,
);
});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment