function createRafLoop() {

    var nextTick = null;
    var queue = [];
    var map = {};
    var raf = (global.requestAnimationFrame
      || global.webkitRequestAnimationFrame
      || global.mozRequestAnimationFrame
      || global.msRequestAnimationFrame
      || function (cb) {
        return global.setTimeout(cb, 16);
      }
    ).bind(global);

    function add(type, id, readCallback, writeCallback) {

      // First, let's check if an item has been added to the queues with the
      // same id and remove it.
      var currentIndex = queue.indexOf(type + id);
      if (currentIndex > -1) {
        queue.splice(currentIndex, 1);
      }

      // Add all move/scroll event callbacks to the beginning of the queue
      // and other callbacks to the end of the queue.
      type === rafQueueMove || type === rafQueueScroll ? queue.unshift(type + id) : queue.push(type + id);
      map[type + id] = [readCallback, writeCallback];

      // Finally, let's kickstart the next tick if it is not running yet.
      !nextTick && (nextTick = raf(flush));

    }

    function cancel(type, id) {

      // Let's check if an item has been added to the queue with the id and
      // if so -> remove it.
      var currentIndex = queue.indexOf(type + id);
      if (currentIndex > -1) {
        queue.splice(currentIndex, 1);
        map[type + id] = undefined;
      }

    }

    function flush() {

      var maxBatchSize = +Grid._maxRafBatchSize || 100;
      var batch = queue.splice(0, Math.min(maxBatchSize, queue.length));
      var batchMap = {};
      var i;

      // Reset ticker.
      nextTick = null;

      // Create batch map and clear map items.
      for (i = 0; i < batch.length; i++) {
        batchMap[batch[i]] = map[batch[i]];
        map[batch[i]] = undefined;
      }

      // Process read callbacks.
      for (i = 0; i < batch.length; i++) {
        batchMap[batch[i]][0]();
      }

      // Process write callbacks.
      for (i = 0; i < batch.length; i++) {
        batchMap[batch[i]][1]();
      }

      // Restart the ticker if needed.
      if (!nextTick && queue.length) {
        nextTick = raf(flush);
      }

    }

    return {
      add: add,
      cancel: cancel
    };

  }
/**
   * Returns a raf loop queue system that allows pushing callbacks to either
   * the read queue or the write queue.
   *
   * @private
   * @returns {Object}
   */
Returns a raf loop queue system that allows pushing callbacks to either
the read queue or the write queue.

@private
@returns {Object}
Returns a raf loop queue system that allows pushing callbacks to either the read queue or the write queue . @private @returns { Object }
function createRafLoop() {
    var nextTick = null;
    var queue = [];
    var map = {};
    var raf = (global.requestAnimationFrame
      || global.webkitRequestAnimationFrame
      || global.mozRequestAnimationFrame
      || global.msRequestAnimationFrame
      || function (cb) {
        return global.setTimeout(cb, 16);
      }
    ).bind(global);
    function add(type, id, readCallback, writeCallback) {
      var currentIndex = queue.indexOf(type + id);
      if (currentIndex > -1) {
        queue.splice(currentIndex, 1);
      }
      type === rafQueueMove || type === rafQueueScroll ? queue.unshift(type + id) : queue.push(type + id);
      map[type + id] = [readCallback, writeCallback];
      !nextTick && (nextTick = raf(flush));
    }
    function cancel(type, id) {
      var currentIndex = queue.indexOf(type + id);
      if (currentIndex > -1) {
        queue.splice(currentIndex, 1);
        map[type + id] = undefined;
      }
    }
    function flush() {
      var maxBatchSize = +Grid._maxRafBatchSize || 100;
      var batch = queue.splice(0, Math.min(maxBatchSize, queue.length));
      var batchMap = {};
      var i;
      nextTick = null;
      for (i = 0; i < batch.length; i++) {
        batchMap[batch[i]] = map[batch[i]];
        map[batch[i]] = undefined;
      }
      for (i = 0; i < batch.length; i++) {
        batchMap[batch[i]][0]();
      }
      for (i = 0; i < batch.length; i++) {
        batchMap[batch[i]][1]();
      }
      if (!nextTick && queue.length) {
        nextTick = raf(flush);
      }
    }
    return {
      add: add,
      cancel: cancel
    };
  }
function createRafLoop ( ) { var nextTick = null ; var queue = [ ] ; var map = { } ; var raf = ( global . requestAnimationFrame || global . webkitRequestAnimationFrame || global . mozRequestAnimationFrame || global . msRequestAnimationFrame || function ( cb ) { return global . setTimeout ( cb , 16 ) ; } ) . bind ( global ) ; function add ( type , id , readCallback , writeCallback ) { var currentIndex = queue . indexOf ( type + id ) ; if ( currentIndex > - 1 ) { queue . splice ( currentIndex , 1 ) ; } type === rafQueueMove || type === rafQueueScroll ? queue . unshift ( type + id ) : queue . push ( type + id ) ; map [ type + id ] = [ readCallback , writeCallback ] ; ! nextTick && ( nextTick = raf ( flush ) ) ; } function cancel ( type , id ) { var currentIndex = queue . indexOf ( type + id ) ; if ( currentIndex > - 1 ) { queue . splice ( currentIndex , 1 ) ; map [ type + id ] = undefined ; } } function flush ( ) { var maxBatchSize = + Grid . _maxRafBatchSize || 100 ; var batch = queue . splice ( 0 , Math . min ( maxBatchSize , queue . length ) ) ; var batchMap = { } ; var i ; nextTick = null ; for ( i = 0 ; i < batch . length ; i ++ ) { batchMap [ batch [ i ] ] = map [ batch [ i ] ] ; map [ batch [ i ] ] = undefined ; } for ( i = 0 ; i < batch . length ; i ++ ) { batchMap [ batch [ i ] ] [ 0 ] ( ) ; } for ( i = 0 ; i < batch . length ; i ++ ) { batchMap [ batch [ i ] ] [ 1 ] ( ) ; } if ( ! nextTick && queue . length ) { nextTick = raf ( flush ) ; } } return { add : add , cancel : cancel } ; }
Returns a raf loop queue system that allows pushing callbacks to either
 the read queue or the write queue.
Returns a raf loop queue system that allows pushing callbacks to either the read queue or the write queue .
// First, let's check if an item has been added to the queues with the // same id and remove it. // Add all move/scroll event callbacks to the beginning of the queue // and other callbacks to the end of the queue. // Finally, let's kickstart the next tick if it is not running yet. // Let's check if an item has been added to the queue with the id and // if so -> remove it. // Reset ticker. // Create batch map and clear map items. // Process read callbacks. // Process write callbacks. // Restart the ticker if needed.