Queue.html 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-util-Queue'>/**
  19. </span> * An internal Queue class.
  20. * @private
  21. */
  22. Ext.define('Ext.util.Queue', {
  23. constructor: function() {
  24. this.clear();
  25. },
  26. add : function(obj) {
  27. var me = this,
  28. key = me.getKey(obj);
  29. if (!me.map[key]) {
  30. ++me.length;
  31. me.items.push(obj);
  32. me.map[key] = obj;
  33. }
  34. return obj;
  35. },
  36. <span id='Ext-util-Queue-method-clear'> /**
  37. </span> * Removes all items from the collection.
  38. */
  39. clear : function(){
  40. var me = this,
  41. items = me.items;
  42. me.items = [];
  43. me.map = {};
  44. me.length = 0;
  45. return items;
  46. },
  47. contains: function (obj) {
  48. var key = this.getKey(obj);
  49. return this.map.hasOwnProperty(key);
  50. },
  51. <span id='Ext-util-Queue-method-getCount'> /**
  52. </span> * Returns the number of items in the collection.
  53. * @return {Number} the number of items in the collection.
  54. */
  55. getCount : function(){
  56. return this.length;
  57. },
  58. getKey : function(obj){
  59. return obj.id;
  60. },
  61. <span id='Ext-util-Queue-method-remove'> /**
  62. </span> * Remove an item from the collection.
  63. * @param {Object} obj The item to remove.
  64. * @return {Object} The item removed or false if no item was removed.
  65. */
  66. remove : function(obj){
  67. var me = this,
  68. key = me.getKey(obj),
  69. items = me.items,
  70. index;
  71. if (me.map[key]) {
  72. index = Ext.Array.indexOf(items, obj);
  73. Ext.Array.erase(items, index, 1);
  74. delete me.map[key];
  75. --me.length;
  76. }
  77. return obj;
  78. }
  79. });</pre>
  80. </body>
  81. </html>