Skip to content

Commit

Permalink
Let debounce trigger on leading and trailing edge
Browse files Browse the repository at this point in the history
  • Loading branch information
jpbede committed Dec 12, 2024
1 parent 6b6e750 commit d871945
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/common/util/debounce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
// leading edge and on the trailing.

export const debounce = <T extends any[]>(
func: (...args: T) => void,
Expand All @@ -14,9 +14,7 @@ export const debounce = <T extends any[]>(
const debouncedFunc = (...args: T): void => {
const later = () => {
timeout = undefined;
if (!immediate) {
func(...args);
}
func(...args);
};
const callNow = immediate && !timeout;
clearTimeout(timeout);
Expand Down

0 comments on commit d871945

Please sign in to comment.