core3-utils

@wixc3/patterns on Github

Home > @wixc3/patterns > Debouncer

Debouncer class

Cancelable debouncing of calls to trigger

Signature:

export declare class Debouncer<T extends (...args: any[]) => any> 

Example 1

waitTime
const debounced = new Debouncer(a => console.log(a), 1, 100)
debounce.trigger('first')
debounce.trigger('second')
// after 1ms
// => 'second'

Example 2

maxWaitTime
const debounced = new Debouncer(a => console.log(a), 3, 4)
debounce.trigger('first')
// after 1ms
debounce.trigger('second')
// after 1ms
// => 'second'
debounce.trigger('third')
// after 2ms, 4ms elapsed since the first trigger
// => 'third'

Constructors

Constructor Modifiers Description
[(constructor)(cb, waitTime, maxWaitTime)](/core3-utils/patterns.debouncer._constructor_.html) Constructs a new instance of the `Debouncer` class

Methods

Method Modifiers Description
[cancel()](/core3-utils/patterns.debouncer.cancel.html) Cancels pending invocation of cb
[trigger(args)](/core3-utils/patterns.debouncer.trigger.html)