ui-router-core
Version:
UI-Router Core: Framework agnostic, State-based routing for JavaScript Single Page Apps
44 lines • 1.28 kB
JavaScript
/**
* @module common
*/ /** for typedoc */
var Queue = (function () {
function Queue(_items, _limit) {
if (_items === void 0) { _items = []; }
if (_limit === void 0) { _limit = null; }
this._items = _items;
this._limit = _limit;
}
Queue.prototype.enqueue = function (item) {
var items = this._items;
items.push(item);
if (this._limit && items.length > this._limit)
items.shift();
return item;
};
Queue.prototype.dequeue = function () {
if (this.size())
return this._items.splice(0, 1)[0];
};
Queue.prototype.clear = function () {
var current = this._items;
this._items = [];
return current;
};
Queue.prototype.size = function () {
return this._items.length;
};
Queue.prototype.remove = function (item) {
var idx = this._items.indexOf(item);
return idx > -1 && this._items.splice(idx, 1)[0];
};
Queue.prototype.peekTail = function () {
return this._items[this._items.length - 1];
};
Queue.prototype.peekHead = function () {
if (this.size())
return this._items[0];
};
return Queue;
}());
export { Queue };
//# sourceMappingURL=queue.js.map