Locations: Use a reusable throttled function
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user