mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2026-09-03 20:53:09 -05:00
16 lines
431 B
TypeScript
16 lines
431 B
TypeScript
export function Debounce (config: { timeoutMS: number }) {
|
|
const timeoutRefKey = Symbol('debounce-timeout')
|
|
|
|
return function (_target, _key, descriptor: PropertyDescriptor) {
|
|
const original = descriptor.value
|
|
|
|
descriptor.value = function (...args: any[]) {
|
|
clearTimeout(this[timeoutRefKey])
|
|
|
|
this[timeoutRefKey] = setTimeout(() => {
|
|
original.apply(this, args)
|
|
}, config.timeoutMS)
|
|
}
|
|
}
|
|
}
|