定义于:debouncer.ts:68
一个创建防抖函数的类。
防抖确保函数仅在其最后一次调用后经过一定时间后才执行。 这对于处理频繁事件(如窗口大小调整、滚动事件或输入更改)非常有用,在这些情况下,您希望限制执行速率。
可以将防抖函数配置为在延迟期开始时(前沿)或结束时(后沿,默认)执行。 等待期间的每次新调用都将重置计时器。
const debouncer = new Debouncer((value: string) => {
saveToDatabase(value);
}, { wait: 500 });
// 仅在没有新输入 500 毫秒后保存
inputElement.addEventListener('input', () => {
debouncer.maybeExecute(inputElement.value);
});
const debouncer = new Debouncer((value: string) => {
saveToDatabase(value);
}, { wait: 500 });
// 仅在没有新输入 500 毫秒后保存
inputElement.addEventListener('input', () => {
debouncer.maybeExecute(inputElement.value);
});
• TFn extends AnyFunction
new Debouncer<TFn>(fn, initialOptions): Debouncer<TFn>
new Debouncer<TFn>(fn, initialOptions): Debouncer<TFn>
定义于:debouncer.ts:75
TFn
DebouncerOptions<TFn>
Debouncer<TFn>
cancel(): void
cancel(): void
定义于:debouncer.ts:160
取消任何待处理的执行
void
getEnabled(): boolean
getEnabled(): boolean
定义于:debouncer.ts:107
返回防抖��的当前启用状态
boolean
getExecutionCount(): number
getExecutionCount(): number
定义于:debouncer.ts:171
返回函数已执行的次数
number
getIsPending(): boolean
getIsPending(): boolean
定义于:debouncer.ts:178
如果正在防抖,则返回 true
boolean
getOptions(): Required<DebouncerOptions<TFn>>
getOptions(): Required<DebouncerOptions<TFn>>
定义于:debouncer.ts:100
返回当前防抖器选项
Required<DebouncerOptions<TFn>>
getWait(): number
getWait(): number
定义于:debouncer.ts:114
返回当前等待时间(以毫秒为单位)
number
maybeExecute(...args): void
maybeExecute(...args): void
定义于:debouncer.ts:122
尝试执行防抖函数 如果已有调用正在进行,则会将其排队
...Parameters<TFn>
void
setOptions(newOptions): void
setOptions(newOptions): void
定义于:debouncer.ts:88
更新防抖器选项
Partial<DebouncerOptions<TFn>>
void