]> git.localhorst.tv Git - alttp.git/blob - resources/js/helpers/debounce.js
tournament/guild connection
[alttp.git] / resources / js / helpers / debounce.js
1 const debounce = (func, wait, immediate) => {
2         let timeout = null;
3
4         return (...args) => {
5                 const context = this;
6
7                 const later = () => {
8                         timeout = null;
9                         if (!immediate) func.apply(context, args);
10                 };
11
12                 const callNow = immediate && !timeout;
13
14                 clearTimeout(timeout);
15
16                 timeout = setTimeout(later, wait);
17
18                 if (callNow) func.apply(context, args);
19         };
20 };
21
22 export default debounce;