mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2024-11-27 03:00:38 -06:00
17 lines
396 B
TypeScript
17 lines
396 B
TypeScript
export function Debounce (config: { timeoutMS: number }) {
|
|
let timeoutRef: NodeJS.Timeout
|
|
|
|
return function (_target, _key, descriptor: PropertyDescriptor) {
|
|
const original = descriptor.value
|
|
|
|
descriptor.value = function (...args: any[]) {
|
|
clearTimeout(timeoutRef)
|
|
|
|
timeoutRef = setTimeout(() => {
|
|
original.apply(this, args)
|
|
|
|
}, config.timeoutMS)
|
|
}
|
|
}
|
|
}
|