fix: replay completion motion reliably
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
type CompletionId = string
|
||||
|
||||
type CompletionTimer = number
|
||||
|
||||
export function createCompletionPulse(
|
||||
activate: (id: CompletionId) => void,
|
||||
deactivate: (id: CompletionId) => void,
|
||||
duration = 420,
|
||||
) {
|
||||
const timers = new Map<CompletionId, CompletionTimer>()
|
||||
|
||||
return (id: CompletionId) => {
|
||||
const previous = timers.get(id)
|
||||
if (previous !== undefined) {
|
||||
window.clearTimeout(previous)
|
||||
deactivate(id)
|
||||
}
|
||||
window.requestAnimationFrame(() => {
|
||||
activate(id)
|
||||
timers.set(id, window.setTimeout(() => {
|
||||
deactivate(id)
|
||||
timers.delete(id)
|
||||
}, duration))
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user