You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
16 lines
395 B
TypeScript
16 lines
395 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)
|
|||
}
|
|||
}
|
|||
}
|