Files
PeerTube/server/core/helpers/debounce.ts
T
Chocobozzz 83074e6b91 Fix debounce of same function
Use a symbol to have a unique property
2026-07-13 15:50:17 +02:00

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)
}
}
}