Skip to content

Commit

Permalink
use reduce in delete logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mbwatson committed May 4, 2024
1 parent 463cd6b commit a7c3c62
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/context/map-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,16 @@ export const LayersProvider = ({ children }) => {
return

Check warning on line 49 in src/context/map-context.js

View workflow job for this annotation

GitHub Actions / eslint

Missing semicolon
}
const thisPosition = defaultModelLayers[index].state.order

Check warning on line 51 in src/context/map-context.js

View workflow job for this annotation

GitHub Actions / eslint

Missing semicolon
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

Check warning on line 54 in src/context/map-context.js

View workflow job for this annotation

GitHub Actions / eslint

Missing semicolon
}
if (l.state.order > thisPosition) {
l.state.order -= 1;
}
acc.push(l)

Check warning on line 59 in src/context/map-context.js

View workflow job for this annotation

GitHub Actions / eslint

Missing semicolon
return acc

Check warning on line 60 in src/context/map-context.js

View workflow job for this annotation

GitHub Actions / eslint

Missing semicolon
}, [])

Check warning on line 61 in src/context/map-context.js

View workflow job for this annotation

GitHub Actions / eslint

Missing semicolon

setDefaultModelLayers(newLayers)

Check warning on line 63 in src/context/map-context.js

View workflow job for this annotation

GitHub Actions / eslint

Missing semicolon
/* todo: update `layer.state.order`s
Expand Down

0 comments on commit a7c3c62

Please sign in to comment.