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 }) => { ...@@ -54,7 +54,7 @@ export const fetchReport = ({ state, dispatch, commit }) => {
} }
Visibility.change(() => { Visibility.change(() => {
if (!Visibility.hidden()) { if (!Visibility.hidden() && state.isLoading) {
dispatch('restartPolling'); dispatch('restartPolling');
} else { } else {
dispatch('stopPolling'); dispatch('stopPolling');
...@@ -62,14 +62,17 @@ export const fetchReport = ({ state, dispatch, commit }) => { ...@@ -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) { if (status === httpStatusCodes.OK) {
commit(types.RECEIVE_REPORT_SUCCESS, data); 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); commit(types.RECEIVE_REPORT_ERROR);
dispatch('stopPolling');
}; };
// prevent babel-plugin-rewire from generating an invalid default during karma tests // prevent babel-plugin-rewire from generating an invalid default during karma tests
......
...@@ -89,7 +89,7 @@ describe('Accessibility Reports actions', () => { ...@@ -89,7 +89,7 @@ describe('Accessibility Reports actions', () => {
{ status: 200, data: mockReport }, { status: 200, data: mockReport },
localState, localState,
[{ type: types.RECEIVE_REPORT_SUCCESS, payload: mockReport }], [{ type: types.RECEIVE_REPORT_SUCCESS, payload: mockReport }],
[], [{ type: 'stopPolling' }],
done, done,
); );
}); });
...@@ -113,7 +113,7 @@ describe('Accessibility Reports actions', () => { ...@@ -113,7 +113,7 @@ describe('Accessibility Reports actions', () => {
null, null,
localState, localState,
[{ type: types.RECEIVE_REPORT_ERROR }], [{ type: types.RECEIVE_REPORT_ERROR }],
[], [{ type: 'stopPolling' }],
done, 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