Skip to content

Commit

Permalink
fix(core): zero as debounce timeout id
Browse files Browse the repository at this point in the history
  • Loading branch information
johannschopplich committed Jul 9, 2024
1 parent ffd2f03 commit 24fe346
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/core/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ export function debounce<T extends (...args: any[]) => void>(
fn: T,
delay: number,
) {
let timeout: ReturnType<typeof setTimeout> | undefined
let timeoutId: number | undefined

return function (...args: Parameters<T>) {
if (timeout)
clearTimeout(timeout)
if (timeoutId != null)
clearTimeout(timeoutId)

timeout = setTimeout(() => {
timeout = undefined
timeoutId = (setTimeout as Window['setTimeout'])(() => {
fn(...args)
timeoutId = undefined
}, delay)
}
}

0 comments on commit 24fe346

Please sign in to comment.