Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. /**
  2. * Created by michal on 23.06.2017.
  3. */
  4. export default function(func, wait, immediate) {
  5. let timeout;
  6.  
  7. return (...args) => {
  8. const context = this;
  9.  
  10. const later = () => {
  11. timeout = null;
  12.  
  13. if (!immediate) {
  14. func.apply(context, args);
  15. }
  16. };
  17.  
  18. const callNow = immediate && !timeout;
  19. clearTimeout(timeout);
  20. timeout = setTimeout(later, wait);
  21.  
  22. if (callNow) {
  23. func.apply(context, args);
  24. }
  25. };
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement