Locations: Use a reusable throttled function

This commit is contained in:
2020-02-26 16:05:35 +01:00
parent 42d67a4bc9
commit c9fd287609
2 changed files with 27 additions and 15 deletions

View File

@@ -14,7 +14,6 @@
// Variables
const transitionDuration = 800
let clickOrigin = Date.now()
let filterLocations
let continentsToDisplay = []
let continentsFiltered = []
@@ -25,14 +24,10 @@
continentsFiltered = [...continentsToDisplay]
// Filter by continent
// detects if click difference if too short
const toggleContinents = (event, continent) => {
if (Date.now() - clickOrigin < transitionDuration) {
return
}
// Detects if click difference if too short with a throttled function
const toggleContinents = fn.throttled((event, continent) => {
continentsFiltered = (!continent) ? [...continentsToDisplay] : [continent]
clickOrigin = Date.now()
}
}, transitionDuration)
/*