Skip to content
This repository was archived by the owner on Aug 23, 2022. It is now read-only.

Commit d20b469

Browse files
committed
Ensuring that flushing a debounced function handles delayed function (if exists) correctly. Fixes #813
1 parent 58fa7cc commit d20b469

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/utils/debounce.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ export default function debounce(func, delay) {
1313
timeout = setTimeout(laterFunc, delay);
1414
};
1515

16-
debouncedFunc.flush = () => laterFunc();
16+
debouncedFunc.flush = () => {
17+
clearTimeout(timeout);
18+
if (laterFunc) laterFunc();
19+
};
1720

1821
return debouncedFunc;
1922
}

0 commit comments

Comments
 (0)