Report an issue
Class

CKEDITOR.tools.buffers.event

class since 4.11.0

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

Filtering

Properties

  • private readonly

    _context : Mixed

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

  • private readonly

    _minInterval : Number

    The minimal interval (in milliseconds) between the calls.

  • private

    _scheduledTimer : Number

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

    Defaults to 0

Methods

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

    Creates a new instance of the buffer.

    Parameters

    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).

    Returns

    event
  • input( [ args ] )

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

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

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

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

    Can be easily used with events:

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

    Parameters

    [ args ] : Mixed[]
  • reset()

    Resets the buffer state and cancels any pending calls.

  • private

    _call()

    Performs an actual call.

  • private

    _clearTimer()

    Cancels the deferred timeout.

  • private

    _reschedule() → Boolean | undefined

    Called when the function call should be rescheduled.

    Returns

    Boolean | undefined

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