123456789101112131415161718192021222324 |
- export const debounced = (fn,delay = 100,promptly) => {
- let timer = null;
- return function(...args) {
-
- if(promptly) {
-
- if(!timer) fn.apply(this,args);
- if(timer) {
- clearTimeout(timer)
- }
- timer = setTimeout(() => {
- timer = null;
- },delay)
- }else {
- if(timer) {
- clearTimeout(timer)
- }
- timer = setTimeout(() => {
- fn.apply(this,args);
- },delay)
- }
- }
- }
|