|
|
@ -8,10 +8,17 @@ import { |
|
|
const debounce = (fn, delay = 1000) => { |
|
|
const debounce = (fn, delay = 1000) => { |
|
|
let timer = null; |
|
|
let timer = null; |
|
|
return function (...args) { |
|
|
return function (...args) { |
|
|
if (timer) clearTimeout(timer); |
|
|
return new Promise((resolve, reject) => { |
|
|
timer = setTimeout(() => { |
|
|
if (timer) clearTimeout(timer); |
|
|
fn.apply(this, args); |
|
|
timer = setTimeout(() => { |
|
|
}, delay); |
|
|
try { |
|
|
|
|
|
const result = fn.apply(this, args); |
|
|
|
|
|
resolve(result); |
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
reject(error); |
|
|
|
|
|
} |
|
|
|
|
|
}, delay); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|