Skip to content

Commit

Permalink
Added debounce utility function for debouncing side-effects and events
Browse files Browse the repository at this point in the history
  • Loading branch information
CMCDragonkai committed Feb 18, 2022
1 parent 08553d1 commit 7e93923
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,17 @@ function arrayUnset<T>(items: Array<T>, item: T) {
}
}

function debounce<P extends any[]>(
f: (...params: P) => any,
timeout: number = 0
): (...param: P) => void {
let timer: ReturnType<typeof setTimeout>;
return function (this: any, ...args: any[]) {
clearTimeout(timer);
timer = setTimeout(() => f.apply(this, args), timeout);
};
}

export {
getDefaultNodePath,
never,
Expand All @@ -220,4 +231,5 @@ export {
timerStop,
arraySet,
arrayUnset,
debounce
};

0 comments on commit 7e93923

Please sign in to comment.