From 61fed6904aea0d4357bdbb7d0d8ad6d04726c662 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Mon, 13 Apr 2020 09:36:24 -0600 Subject: [PATCH] review feedback --- .../maps/public/actions/map_actions.js | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/actions/map_actions.js b/x-pack/legacy/plugins/maps/public/actions/map_actions.js index 43eb73ae8719c..7bfbf5761c5b8 100644 --- a/x-pack/legacy/plugins/maps/public/actions/map_actions.js +++ b/x-pack/legacy/plugins/maps/public/actions/map_actions.js @@ -125,9 +125,21 @@ async function syncDataForAllLayers(dispatch, getState, dataFilters) { export function cancelAllInFlightRequests() { return (dispatch, getState) => { getLayerList(getState()).forEach(layer => { - layer.getInFlightRequestTokens().forEach(requestToken => { - dispatch(cancelRequest(requestToken)); - }); + dispatch(clearDataRequests(layer)); + }); + }; +} + +function clearDataRequests(layer) { + return dispatch => { + layer.getInFlightRequestTokens().forEach(requestToken => { + dispatch(cancelRequest(requestToken)); + }); + dispatch({ + type: UPDATE_LAYER_PROP, + id: layer.getId(), + propName: '__dataRequests', + newValue: [], }); }; } @@ -678,15 +690,7 @@ function updateLayerType(layerId, newLayerType) { if (!layer || layer.getType() === newLayerType) { return; } - layer.getInFlightRequestTokens().forEach(requestToken => { - dispatch(cancelRequest(requestToken)); - }); - dispatch({ - type: UPDATE_LAYER_PROP, - id: layerId, - propName: '__dataRequests', - newValue: [], - }); + dispatch(clearDataRequests(layer)); dispatch({ type: UPDATE_LAYER_PROP, id: layerId,