Report an issue

class since 4.11.0

Throttles input events (or any input calls) and triggers output not more often than once per minInterval.

Unlike this class allows passing custom parameters into the input function. For more information see the Throttling function issue.



  • _args : Mixed[]


    Arguments for the last scheduled call.

    Defaults to []

  • _context : Mixed

    private readonly

    The variable to be used as a context for the output calls.

  • _minInterval : Number

    private readonly

    The minimal interval (in milliseconds) between the calls.

  • _scheduledTimer : Number


    The ID of a delayed function call that will be called after the current interval frame.

    Defaults to 0


  • constructor( minInterval, output, [ contextObj ] ) → event

    Creates a new instance of the buffer.


    minInterval : Number

    The minimum interval between output calls in milliseconds.

    output : Function

    The function that will be executed as output.

    [ contextObj ] : Object

    The object used as context to the listener call (the this object).


  • input( [ args ] )

    Acts as a proxy to the output function given in the constructor, providing function throttling.

    Guarantees that the output function does not get called more often than indicated by the _minInterval.

    If multiple calls occur within a single minInterval time, the most recent input call with its arguments will be used to schedule the next output call, and the previous throttled calls will be discarded.

    The first input call is always executed asynchronously which means that the output call will be executed immediately.

    var buffer = new 200, function( message ) {
        console.log( message );
    } );
    buffer.input( 'foo!' );
    // 'foo!' logged immediately.
    buffer.input( 'bar!' );
    // Nothing logged.
    buffer.input( 'baz!' );
    // Nothing logged.
    // … after 200ms a single 'baz!' will be logged.

    It can be easily used with events:

    var buffer = new 200, function( evt ) {
        console.log( );
    } );
    editor.on( 'key', buffer.input );
    // Note: There is no need to bind the buffer as a context.


    [ args ] : Mixed[]
  • reset()

    Resets the buffer state and cancels any pending calls.

  • _call()


    Performs an actual call.

  • _clearTimer()


    Cancels the deferred timeout.

  • _reschedule() → Boolean | undefined


    Called when the function call should be rescheduled.


    Boolean | undefined

    If it returns false, the the parent call will be stopped.