clear old engine ids (#415)

* clear old engine ids

* animate re-execute and deffer execution for user typing
This commit is contained in:
Kurt Hutten
2023-09-08 17:50:37 +10:00
committed by GitHub
parent 0120a89d9c
commit 3bccae492d
5 changed files with 304 additions and 188 deletions

View File

@ -56,6 +56,27 @@ export function throttle<T>(
return throttled
}
// takes a function and executes it after the wait time, if the function is called again before the wait time is up, the timer is reset
export function defferExecution<T>(func: (args: T) => any, wait: number) {
let timeout: ReturnType<typeof setTimeout> | null
let latestArgs: T
function later() {
timeout = null
func(latestArgs)
}
function deffered(args: T) {
latestArgs = args
if (timeout) {
clearTimeout(timeout)
}
timeout = setTimeout(later, wait)
}
return deffered
}
export function getNormalisedCoordinates({
clientX,
clientY,