Skip to content

Commit

Permalink
fix: fix debounce
Browse files Browse the repository at this point in the history
  • Loading branch information
vikiboss committed Jun 24, 2024
1 parent 031b643 commit cfb347c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/utils/debounce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function debounce<T extends AnyFunc>(fn: T, options: DebounceOptions = {}
const debounced = function (this: ThisParameterType<T>, ...args: Parameters<T>) {
const invokeLeading = leading && !leadingInvoked

const later = () => {
const invoke = () => {
timeoutId = null
if (trailing && !leadingInvoked) fn.apply(this, args)
leadingInvoked = false
Expand All @@ -43,12 +43,12 @@ export function debounce<T extends AnyFunc>(fn: T, options: DebounceOptions = {}
fn.apply(this, args)
}

timeoutId = setTimeout(() => later(), wait)
timeoutId = setTimeout(invoke, wait)

if (!leading && !trailing && !timeoutId) {
fn.apply(this, args)
leadingInvoked = false
}
// if (!leading && !trailing) {
// fn.apply(this, args)
// leadingInvoked = false
// }
}

debounced.clear = () => {
Expand Down

0 comments on commit cfb347c

Please sign in to comment.