Guest User

Untitled

a guest
Oct 23rd, 2019
103
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const debounce = (func, wait = 100, args, immediate) => {
  2. let timeout;
  3.  
  4. return () => {
  5. const context = this;
  6. const callNow = immediate && !timeout;
  7. const later = () => {
  8. timeout = null;
  9. if (!immediate) func.apply(context, args);
  10. };
  11.  
  12. clearTimeout(timeout);
  13. timeout = setTimeout(later, wait);
  14.  
  15. if (callNow) func.apply(context, args);
  16. };
  17. };
  18.  
  19. export default debounce;
RAW Paste Data