Добавил debouncing

jwt
Sipachev Igor 2 years ago
parent 7a84ff4a74
commit ec41e91388
  1. 18
      api/debouncing.ts

@ -0,0 +1,18 @@
export const debouncing = async (time: number = 1000) => {
return new Promise((resolve, reject) => {
const timerId = setTimeout(() => {
resolve(true)
}, time)
const listener = (event: any) => {
if (event.detail === timerId) {
return
}
clearTimeout(timerId)
reject(new Error('locked!!!' + timerId))
document.removeEventListener('debiuncing.clean', listener);
}
document.addEventListener('debiuncing.clean', listener)
const event = new CustomEvent('debiuncing.clean', { detail: timerId });
document.dispatchEvent(event);
})
}
Loading…
Cancel
Save