All files / src/utils requestAnimation.js

100% Statements 4/4
50% Branches 1/2
100% Functions 2/2
100% Lines 4/4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30                                        3x 3x 3x 3x            
/**
* Copyright 2018, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
 
 
/**
 * Perform updates in a browser-requested animation frame.
 * If this is called multiple times before a new animation frame was provided,
 * the subsequent calls will be dropped.
 * Thus, make sure to use the current data in the callback
 * (it might have been updated once the callback fired)
 *
 * @param {Object} Class instance to bind the callback too
 * @param {Function} callback Function to be called in the animation frame
 */
function requestAnimation(instance, callback) {
  Eif (instance.nextFrame === undefined) {
    instance.nextFrame = window.requestAnimationFrame(function(){
      callback();
      this.nextFrame = undefined;
    }.bind(instance));
  }
}
 
export default requestAnimation;