esa-cli
Version:
A CLI for operating Alibaba Cloud ESA Functions and Pages.
19 lines (18 loc) • 512 B
JavaScript
export default function debounce(func, wait, immediate = false) {
let timeoutId = null;
return (...args) => {
const later = () => {
timeoutId = null;
if (!immediate)
func(...args);
};
const shouldCallNow = immediate && timeoutId === null;
if (timeoutId !== null) {
clearTimeout(timeoutId);
}
timeoutId = setTimeout(later, wait);
if (shouldCallNow) {
func(...args);
}
};
}