Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  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;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement