-
-
Save ar5had/63d156469b08d559dacb460bdadeb1e7 to your computer and use it in GitHub Desktop.
Revisions
-
ca0v revised this gist
Nov 1, 2019 . 1 changed file with 12 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,14 @@ // ts 3.6x function debounce<T extends Function>(cb: T, wait = 20) { let h = 0; let callable = (...args: any) => { clearTimeout(h); h = setTimeout(() => cb(...args), wait); }; return <T>(<any>callable); } // usage let f = debounce((a: string, b: number, c?: number) => console.log(a.length + b + c || 0)); f("hi", 1, 1); f("world", 1); -
ca0v created this gist
Feb 14, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ function debounce(func: () => void, wait = 50) { let h: number; return () => { clearTimeout(h); h = setTimeout(() => func(), wait); }; }