X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/7a654f8d43fdb43d78b63d90528bed6e86b608cc..f562e4c6e5fac7bcb445985b99acbea4d706e6f0:/docs/source/HashMap.html?ds=sidebyside diff --git a/docs/source/HashMap.html b/docs/source/HashMap.html index 3ad620f6..6546b677 100644 --- a/docs/source/HashMap.html +++ b/docs/source/HashMap.html @@ -1,5 +1,22 @@ -Sencha Documentation Project
/**
- * @class Ext.util.HashMap
+
+
+
+  
+  The source code
+  
+  
+  
+  
+
+
+  
/**
+ * @class Ext.util.HashMap
  * <p>
  * Represents a collection of a set of key and value pairs. Each key in the HashMap
  * must be unique, the same key cannot exist twice. Access to items is provided via
@@ -20,26 +37,30 @@ map.each(function(key, value, length){
  * there is no guarantee when iterating over the items that they will be in any particular
  * order. If this is required, then use a {@link Ext.util.MixedCollection}.
  * </p>
- * @constructor
- * @param {Object} config The configuration options
  */
 Ext.define('Ext.util.HashMap', {
+    mixins: {
+        observable: 'Ext.util.Observable'
+    },
 
-    /**
+    /**
      * @cfg {Function} keyFn A function that is used to retrieve a default key for a passed object.
      * A default is provided that returns the <b>id</b> property on the object. This function is only used
      * if the add method is called with a single argument.
      */
 
-    mixins: {
-        observable: 'Ext.util.Observable'
-    },
-
+    /**
+     * Creates new HashMap.
+     * @param {Object} config (optional) Config object.
+     */
     constructor: function(config) {
-        var me = this;
+        config = config || {};
+        
+        var me = this,
+            keyFn = config.keyFn;
 
         me.addEvents(
-            /**
+            /**
              * @event add
              * Fires when a new item is added to the hash
              * @param {Ext.util.HashMap} this.
@@ -47,13 +68,13 @@ Ext.define('Ext.util.HashMap', {
              * @param {Object} value The value of the added item.
              */
             'add',
-            /**
+            /**
              * @event clear
              * Fires when the hash is cleared.
              * @param {Ext.util.HashMap} this.
              */
             'clear',
-            /**
+            /**
              * @event remove
              * Fires when an item is removed from the hash.
              * @param {Ext.util.HashMap} this.
@@ -61,7 +82,7 @@ Ext.define('Ext.util.HashMap', {
              * @param {Object} value The value of the removed item.
              */
             'remove',
-            /**
+            /**
              * @event replace
              * Fires when an item is replaced in the hash.
              * @param {Ext.util.HashMap} this.
@@ -74,9 +95,13 @@ Ext.define('Ext.util.HashMap', {
 
         me.mixins.observable.constructor.call(me, config);
         me.clear(true);
+        
+        if (keyFn) {
+            me.getKey = keyFn;
+        }
     },
 
-    /**
+    /**
      * Gets the number of items in the hash.
      * @return {Number} The number of items in the hash.
      */
@@ -84,7 +109,7 @@ Ext.define('Ext.util.HashMap', {
         return this.length;
     },
 
-    /**
+    /**
      * Implementation for being able to extract the key from an object if only
      * a single argument is passed.
      * @private
@@ -102,9 +127,8 @@ Ext.define('Ext.util.HashMap', {
         return [key, value];
     },
 
-    /**
+    /**
      * Extracts the key from an object. This is a default implementation, it may be overridden
-     * @private
      * @param {Object} o The object to get the key from
      * @return {String} The key to use.
      */
@@ -112,7 +136,7 @@ Ext.define('Ext.util.HashMap', {
         return o.id;
     },
 
-    /**
+    /**
      * Adds an item to the collection. Fires the {@link #add} event when complete.
      * @param {String} key <p>The key to associate with the item, or the new item.</p>
      * <p>If a {@link #getKey} implementation was specified for this HashMap,
@@ -132,7 +156,7 @@ Ext.define('Ext.util.HashMap', {
         }
 
         if (me.containsKey(key)) {
-            me.replace(key, value);
+            return me.replace(key, value);
         }
 
         data = me.getData(key, value);
@@ -144,7 +168,7 @@ Ext.define('Ext.util.HashMap', {
         return value;
     },
 
-    /**
+    /**
      * Replaces an item in the hash. If the key doesn't exist, the
      * {@link #add} method will be used.
      * @param {String} key The key of the item.
@@ -165,7 +189,7 @@ Ext.define('Ext.util.HashMap', {
         return value;
     },
 
-    /**
+    /**
      * Remove an item from the hash.
      * @param {Object} o The value of the item to remove.
      * @return {Boolean} True if the item was successfully removed.
@@ -178,7 +202,7 @@ Ext.define('Ext.util.HashMap', {
         return false;
     },
 
-    /**
+    /**
      * Remove an item from the hash.
      * @param {String} key The key to remove.
      * @return {Boolean} True if the item was successfully removed.
@@ -197,7 +221,7 @@ Ext.define('Ext.util.HashMap', {
         return false;
     },
 
-    /**
+    /**
      * Retrieves an item with a particular key.
      * @param {String} key The key to lookup.
      * @return {Object} The value at that key. If it doesn't exist, <tt>undefined</tt> is returned.
@@ -206,7 +230,7 @@ Ext.define('Ext.util.HashMap', {
         return this.map[key];
     },
 
-    /**
+    /**
      * Removes all items from the hash.
      * @return {Ext.util.HashMap} this
      */
@@ -220,7 +244,7 @@ Ext.define('Ext.util.HashMap', {
         return me;
     },
 
-    /**
+    /**
      * Checks whether a key exists in the hash.
      * @param {String} key The key to check for.
      * @return {Boolean} True if they key exists in the hash.
@@ -229,7 +253,7 @@ Ext.define('Ext.util.HashMap', {
         return this.map[key] !== undefined;
     },
 
-    /**
+    /**
      * Checks whether a value exists in the hash.
      * @param {Object} value The value to check for.
      * @return {Boolean} True if the value exists in the dictionary.
@@ -238,7 +262,7 @@ Ext.define('Ext.util.HashMap', {
         return this.containsKey(this.findKey(value));
     },
 
-    /**
+    /**
      * Return all of the keys in the hash.
      * @return {Array} An array of keys.
      */
@@ -246,7 +270,7 @@ Ext.define('Ext.util.HashMap', {
         return this.getArray(true);
     },
 
-    /**
+    /**
      * Return all of the values in the hash.
      * @return {Array} An array of values.
      */
@@ -254,7 +278,7 @@ Ext.define('Ext.util.HashMap', {
         return this.getArray(false);
     },
 
-    /**
+    /**
      * Gets either the keys/values in an array from the hash.
      * @private
      * @param {Boolean} isKey True to extract the keys, otherwise, the value
@@ -272,7 +296,7 @@ Ext.define('Ext.util.HashMap', {
         return arr;
     },
 
-    /**
+    /**
      * Executes the specified function once for each item in the hash.
      * Returning false from the function will cease iteration.
      *
@@ -303,7 +327,7 @@ Ext.define('Ext.util.HashMap', {
         return this;
     },
 
-    /**
+    /**
      * Performs a shallow copy on this hash.
      * @return {Ext.util.HashMap} The new hash object.
      */
@@ -322,7 +346,7 @@ Ext.define('Ext.util.HashMap', {
         return hash;
     },
 
-    /**
+    /**
      * @private
      * Find the key for a value.
      * @param {Object} value The value to find.
@@ -340,4 +364,6 @@ Ext.define('Ext.util.HashMap', {
         return undefined;
     }
 });
-
\ No newline at end of file +
+ +