mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2026-09-03 20:53:09 -05:00
Fix debounce of same function
Use a symbol to have a unique property
This commit is contained in:
@@ -1,13 +1,13 @@
|
|||||||
export function Debounce (config: { timeoutMS: number }) {
|
export function Debounce (config: { timeoutMS: number }) {
|
||||||
let timeoutRef: NodeJS.Timeout
|
const timeoutRefKey = Symbol('debounce-timeout')
|
||||||
|
|
||||||
return function (_target, _key, descriptor: PropertyDescriptor) {
|
return function (_target, _key, descriptor: PropertyDescriptor) {
|
||||||
const original = descriptor.value
|
const original = descriptor.value
|
||||||
|
|
||||||
descriptor.value = function (...args: any[]) {
|
descriptor.value = function (...args: any[]) {
|
||||||
clearTimeout(timeoutRef)
|
clearTimeout(this[timeoutRefKey])
|
||||||
|
|
||||||
timeoutRef = setTimeout(() => {
|
this[timeoutRefKey] = setTimeout(() => {
|
||||||
original.apply(this, args)
|
original.apply(this, args)
|
||||||
}, config.timeoutMS)
|
}, config.timeoutMS)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user