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