Skip to content

Commit

Permalink
move setting of layer type to action creator instead of side effect o…
Browse files Browse the repository at this point in the history
…f UPDATE_SOURCE_PROP
  • Loading branch information
nreese committed Apr 13, 2020
1 parent 4e04bff commit d18d3e7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
28 changes: 27 additions & 1 deletion x-pack/legacy/plugins/maps/public/actions/map_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -663,13 +663,39 @@ export function updateSourceProp(layerId, propName, value, newLayerType) {
layerId,
propName,
value,
newLayerType,
});
if (newLayerType) {
dispatch(updateLayerType(layerId, newLayerType));
}
await dispatch(clearMissingStyleProperties(layerId));
dispatch(syncDataForLayer(layerId));
};
}

function updateLayerType(layerId, newLayerType) {
return (dispatch, getState) => {
const layer = getLayerById(layerId, getState());
if (!layer || layer.getType() === newLayerType) {
return;
}
layer.getInFlightRequestTokens().forEach(requestToken => {
dispatch(cancelRequest(requestToken));
});
dispatch({
type: UPDATE_LAYER_PROP,
id: layerId,
propName: '__dataRequests',
newValue: [],
});
dispatch({
type: UPDATE_LAYER_PROP,
id: layerId,
propName: 'type',
newValue: newLayerType,
});
};
}

export function syncDataForLayer(layerId) {
return async (dispatch, getState) => {
const targetLayer = getLayerById(layerId, getState());
Expand Down
15 changes: 2 additions & 13 deletions x-pack/plugins/maps/public/reducers/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const updateLayerInList = (state, layerId, attribute, newValue) => {
return { ...state, layerList: updatedList };
};

const updateLayerSourceDescriptorProp = (state, layerId, propName, value, newLayerType) => {
const updateLayerSourceDescriptorProp = (state, layerId, propName, value) => {
const { layerList } = state;
const layerIdx = getLayerIndex(layerList, layerId);
const updatedLayer = {
Expand All @@ -84,11 +84,6 @@ const updateLayerSourceDescriptorProp = (state, layerId, propName, value, newLay
[propName]: value,
},
};
if (newLayerType && newLayerType !== layerList[layerIdx].type) {
// clear out data requests for previous layer type
updatedLayer.__dataRequests = [];
updatedLayer.type = newLayerType;
}
const updatedList = [
...layerList.slice(0, layerIdx),
updatedLayer,
Expand Down Expand Up @@ -263,13 +258,7 @@ export function map(state = INITIAL_STATE, action) {
case UPDATE_LAYER_PROP:
return updateLayerInList(state, action.id, action.propName, action.newValue);
case UPDATE_SOURCE_PROP:
return updateLayerSourceDescriptorProp(
state,
action.layerId,
action.propName,
action.value,
action.newLayerType
);
return updateLayerSourceDescriptorProp(state, action.layerId, action.propName, action.value);
case SET_JOINS:
const layerDescriptor = state.layerList.find(
descriptor => descriptor.id === action.layer.getId()
Expand Down

0 comments on commit d18d3e7

Please sign in to comment.