From cfb347c4ac97d7829f46eff352bb8a92c8405b28 Mon Sep 17 00:00:00 2001 From: Viki Date: Mon, 24 Jun 2024 19:45:25 +0800 Subject: [PATCH] fix: fix debounce --- src/utils/debounce.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/utils/debounce.ts b/src/utils/debounce.ts index 106ad0f9..769091e7 100644 --- a/src/utils/debounce.ts +++ b/src/utils/debounce.ts @@ -30,7 +30,7 @@ export function debounce(fn: T, options: DebounceOptions = {} const debounced = function (this: ThisParameterType, ...args: Parameters) { const invokeLeading = leading && !leadingInvoked - const later = () => { + const invoke = () => { timeoutId = null if (trailing && !leadingInvoked) fn.apply(this, args) leadingInvoked = false @@ -43,12 +43,12 @@ export function debounce(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 = () => {