API Docs for: 3.8.0
Show:

File: yui/js/queue-base.js

  1. /**
  2.  * The YUI module contains the components required for building the YUI
  3.  * seed file.  This includes the script loading mechanism, a simple queue,
  4.  * and the core utilities for the library.
  5.  * @module yui
  6.  * @submodule yui-base
  7.  */

  8. /**
  9.  * A simple FIFO queue.  Items are added to the Queue with add(1..n items) and
  10.  * removed using next().
  11.  *
  12.  * @class Queue
  13.  * @constructor
  14.  * @param {MIXED} item* 0..n items to seed the queue.
  15.  */
  16. function Queue() {
  17.     this._init();
  18.     this.add.apply(this, arguments);
  19. }

  20. Queue.prototype = {
  21.     /**
  22.      * Initialize the queue
  23.      *
  24.      * @method _init
  25.      * @protected
  26.      */
  27.     _init: function() {
  28.         /**
  29.          * The collection of enqueued items
  30.          *
  31.          * @property _q
  32.          * @type Array
  33.          * @protected
  34.          */
  35.         this._q = [];
  36.     },

  37.     /**
  38.      * Get the next item in the queue. FIFO support
  39.      *
  40.      * @method next
  41.      * @return {MIXED} the next item in the queue.
  42.      */
  43.     next: function() {
  44.         return this._q.shift();
  45.     },

  46.     /**
  47.      * Get the last in the queue. LIFO support.
  48.      *
  49.      * @method last
  50.      * @return {MIXED} the last item in the queue.
  51.      */
  52.     last: function() {
  53.         return this._q.pop();
  54.     },

  55.     /**
  56.      * Add 0..n items to the end of the queue.
  57.      *
  58.      * @method add
  59.      * @param {MIXED} item* 0..n items.
  60.      * @return {object} this queue.
  61.      */
  62.     add: function() {
  63.         this._q.push.apply(this._q, arguments);

  64.         return this;
  65.     },

  66.     /**
  67.      * Returns the current number of queued items.
  68.      *
  69.      * @method size
  70.      * @return {Number} The size.
  71.      */
  72.     size: function() {
  73.         return this._q.length;
  74.     }
  75. };

  76. Y.Queue = Queue;

  77. YUI.Env._loaderQueue = YUI.Env._loaderQueue || new Queue();


  78.