mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-04-28 20:35:19 +08:00
18 lines
410 B
TypeScript
18 lines
410 B
TypeScript
export default function debounce<T extends (...args: any[]) => void>(
|
|
func: T,
|
|
duration: number
|
|
): T {
|
|
let timeout: NodeJS.Timeout | number | undefined;
|
|
|
|
return function (this: any, ...args) {
|
|
if (!timeout) {
|
|
// eslint-disable-next-line babel/no-invalid-this
|
|
func.apply(this, args);
|
|
|
|
timeout = setTimeout(() => {
|
|
timeout = undefined;
|
|
}, duration);
|
|
}
|
|
} as T;
|
|
}
|