Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const debounce = (func, wait = 100, args, immediate) => {
- let timeout;
- return () => {
- const context = this;
- const callNow = immediate && !timeout;
- const later = () => {
- timeout = null;
- if (!immediate) func.apply(context, args);
- };
- clearTimeout(timeout);
- timeout = setTimeout(later, wait);
- if (callNow) func.apply(context, args);
- };
- };
- export default debounce;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement