From a7c3c620900940d5b6195a8c3eb44b1cacaa8dd3 Mon Sep 17 00:00:00 2001 From: Matt Watson Date: Sat, 4 May 2024 09:55:11 -0400 Subject: [PATCH] use reduce in delete logic --- src/context/map-context.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/context/map-context.js b/src/context/map-context.js index f55ecf65..211bd0ab 100644 --- a/src/context/map-context.js +++ b/src/context/map-context.js @@ -49,13 +49,16 @@ export const LayersProvider = ({ children }) => { return } const thisPosition = defaultModelLayers[index].state.order - const newLayers = [...defaultModelLayers.slice(0, index), ...defaultModelLayers.slice(index + 1)] - .map(l => { - if (l.state.order > thisPosition) { - l.state.order -= 1; - } - return l - }); + const newLayers = defaultModelLayers.reduce((acc, l) => { + if (l.state.order === thisPosition) { + return acc + } + if (l.state.order > thisPosition) { + l.state.order -= 1; + } + acc.push(l) + return acc + }, []) setDefaultModelLayers(newLayers) /* todo: update `layer.state.order`s