Advertisement
xDisfigure

[JS][ES] Action Timeout on keypress

Mar 15th, 2017
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// Wait to load action on typings
  2.  
  3. let typingsTimeout = (callback, time) => {
  4.     return () => {
  5.         if(timeout) {
  6.              clearTimeout(timeout);
  7.         }
  8.  
  9.         timeout = setTimeout(() => {
  10.            callback()
  11.         }, time)
  12.     };
  13. };
  14.  
  15. /// use it like
  16.  
  17. $(domElement).on('keypdown, keyup', typings(() => {
  18.     // do action here
  19. }, 600));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement