Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. // send req after a few seconds have passed since user last wrote in the editor
  2. export default function debounce(a,b,c){
  3. let d,e;
  4. return function(){
  5. function h(){
  6. d=null;
  7. c||(e=a.apply(f,g));
  8. }
  9. let f=this,g=arguments;
  10. return (clearTimeout(d),d=setTimeout(h,b),c&&!d&&(e=a.apply(f,g)),e)
  11. }
  12. }
  13.  
  14.  
  15. // Call it like this (Wait for 1.5s)
  16. debounce(() => {}, 1500);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement