Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / docs / source / AbstractManager.html
index 8dcdc7c..43d119c 100644 (file)
+<!DOCTYPE html>
 <html>
 <head>
-  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    
+  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   <title>The source code</title>
-    <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
-    <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
+  <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
+  <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
+  <style type="text/css">
+    .highlight { display: block; background-color: #ddd; }
+  </style>
+  <script type="text/javascript">
+    function highlight() {
+      document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
+    }
+  </script>
 </head>
-<body  onload="prettyPrint();">
-    <pre class="prettyprint lang-js">/*!
- * Ext JS Library 3.3.0
- * Copyright(c) 2006-2010 Ext JS, Inc.
- * licensing@extjs.com
- * http://www.extjs.com/license
- */
-<div id="cls-Ext.AbstractManager"></div>/**
- * @class Ext.AbstractManager
- * @extends Object
- * Base Manager class - extended by ComponentMgr and PluginMgr
+<body onload="prettyPrint(); highlight();">
+  <pre class="prettyprint lang-js"><span id='Ext-AbstractManager'>/**
+</span> * Base Manager class
  */
-Ext.AbstractManager = Ext.extend(Object, {
+Ext.define('Ext.AbstractManager', {
+
+    /* Begin Definitions */
+
+    requires: ['Ext.util.HashMap'],
+
+    /* End Definitions */
+
     typeName: 'type',
-    
+
     constructor: function(config) {
         Ext.apply(this, config || {});
-        
-        <div id="prop-Ext.AbstractManager-all"></div>/**
+
+<span id='Ext-AbstractManager-property-all'>        /**
+</span>         * @property {Ext.util.HashMap} all
          * Contains all of the items currently managed
-         * @property all
-         * @type Ext.util.MixedCollection
          */
-        this.all = new Ext.util.MixedCollection();
-        
+        this.all = Ext.create('Ext.util.HashMap');
+
         this.types = {};
     },
-    
-    <div id="method-Ext.AbstractManager-get"></div>/**
-     * Returns a component by {@link Ext.Component#id id}.
-     * For additional details see {@link Ext.util.MixedCollection#get}.
-     * @param {String} id The component {@link Ext.Component#id id}
-     * @return Ext.Component The Component, <code>undefined</code> if not found, or <code>null</code> if a
-     * Class was found.
+
+<span id='Ext-AbstractManager-method-get'>    /**
+</span>     * Returns an item by id.
+     * For additional details see {@link Ext.util.HashMap#get}.
+     * @param {String} id The id of the item
+     * @return {Object} The item, undefined if not found.
      */
-    get : function(id){
+    get : function(id) {
         return this.all.get(id);
     },
-    
-    <div id="method-Ext.AbstractManager-register"></div>/**
-     * Registers an item to be managed
-     * @param {Mixed} item The item to register
+
+<span id='Ext-AbstractManager-method-register'>    /**
+</span>     * Registers an item to be managed
+     * @param {Object} item The item to register
      */
     register: function(item) {
+        //&lt;debug&gt;
+        var all = this.all,
+            key = all.getKey(item);
+            
+        if (all.containsKey(key)) {
+            Ext.Error.raise('Registering duplicate id &quot;' + key + '&quot; with this manager');
+        }
+        //&lt;/debug&gt;
         this.all.add(item);
     },
-    
-    <div id="method-Ext.AbstractManager-unregister"></div>/**
-     * Unregisters a component by removing it from this manager
-     * @param {Mixed} item The item to unregister
+
+<span id='Ext-AbstractManager-method-unregister'>    /**
+</span>     * Unregisters an item by removing it from this manager
+     * @param {Object} item The item to unregister
      */
     unregister: function(item) {
-        this.all.remove(item);        
+        this.all.remove(item);
     },
-    
-    <div id="method-Ext.AbstractManager-registerType"></div>/**
-     * <p>Registers a new Component constructor, keyed by a new
-     * {@link Ext.Component#xtype}.</p>
-     * <p>Use this method (or its alias {@link Ext#reg Ext.reg}) to register new
-     * subclasses of {@link Ext.Component} so that lazy instantiation may be used when specifying
-     * child Components.
-     * see {@link Ext.Container#items}</p>
-     * @param {String} xtype The mnemonic string by which the Component class may be looked up.
-     * @param {Constructor} cls The new Component class.
+
+<span id='Ext-AbstractManager-method-registerType'>    /**
+</span>     * Registers a new item constructor, keyed by a type key.
+     * @param {String} type The mnemonic string by which the class may be looked up.
+     * @param {Function} cls The new instance class.
      */
-    registerType : function(type, cls){
+    registerType : function(type, cls) {
         this.types[type] = cls;
         cls[this.typeName] = type;
     },
-    
-    <div id="method-Ext.AbstractManager-isRegistered"></div>/**
-     * Checks if a Component type is registered.
-     * @param {Ext.Component} xtype The mnemonic string by which the Component class may be looked up
+
+<span id='Ext-AbstractManager-method-isRegistered'>    /**
+</span>     * Checks if an item type is registered.
+     * @param {String} type The mnemonic string by which the class may be looked up
      * @return {Boolean} Whether the type is registered.
      */
     isRegistered : function(type){
-        return this.types[type] !== undefined;    
+        return this.types[type] !== undefined;
     },
-    
-    <div id="method-Ext.AbstractManager-create"></div>/**
-     * Creates and returns an instance of whatever this manager manages, based on the supplied type and config object
+
+<span id='Ext-AbstractManager-method-create'>    /**
+</span>     * Creates and returns an instance of whatever this manager manages, based on the supplied type and
+     * config object.
      * @param {Object} config The config object
      * @param {String} defaultType If no type is discovered in the config object, we fall back to this type
-     * @return {Mixed} The instance of whatever this manager is managing
+     * @return {Object} The instance of whatever this manager is managing
      */
     create: function(config, defaultType) {
         var type        = config[this.typeName] || config.type || defaultType,
             Constructor = this.types[type];
-        
-        if (Constructor == undefined) {
-            throw new Error(String.format("The '{0}' type has not been registered with this manager", type));
+
+        //&lt;debug&gt;
+        if (Constructor === undefined) {
+            Ext.Error.raise(&quot;The '&quot; + type + &quot;' type has not been registered with this manager&quot;);
         }
-        
+        //&lt;/debug&gt;
+
         return new Constructor(config);
     },
-    
-    <div id="method-Ext.AbstractManager-onAvailable"></div>/**
-     * Registers a function that will be called when a Component with the specified id is added to the manager. This will happen on instantiation.
-     * @param {String} id The component {@link Ext.Component#id id}
-     * @param {Function} fn The callback function
-     * @param {Object} scope The scope (<code>this</code> reference) in which the callback is executed. Defaults to the Component.
+
+<span id='Ext-AbstractManager-method-onAvailable'>    /**
+</span>     * Registers a function that will be called when an item with the specified id is added to the manager.
+     * This will happen on instantiation.
+     * @param {String} id The item id
+     * @param {Function} fn The callback function. Called with a single parameter, the item.
+     * @param {Object} scope The scope (this reference) in which the callback is executed.
+     * Defaults to the item.
      */
     onAvailable : function(id, fn, scope){
-        var all = this.all;
+        var all = this.all,
+            item;
         
-        all.on("add", function(index, o){
-            if (o.id == id) {
-                fn.call(scope || o, o);
-                all.un("add", fn, scope);
-            }
-        });
+        if (all.containsKey(id)) {
+            item = all.get(id);
+            fn.call(scope || item, item);
+        } else {
+            all.on('add', function(map, key, item){
+                if (key == id) {
+                    fn.call(scope || item, item);
+                    all.un('add', fn, scope);
+                }
+            });
+        }
+    },
+    
+<span id='Ext-AbstractManager-method-each'>    /**
+</span>     * Executes the specified function once for each item in the collection.
+     * @param {Function} fn The function to execute.
+     * @param {String} fn.key The key of the item
+     * @param {Number} fn.value The value of the item
+     * @param {Number} fn.length The total number of items in the collection
+     * @param {Boolean} fn.return False to cease iteration.
+     * @param {Object} scope The scope to execute in. Defaults to `this`.
+     */
+    each: function(fn, scope){
+        this.all.each(fn, scope || this);    
+    },
+    
+<span id='Ext-AbstractManager-method-getCount'>    /**
+</span>     * Gets the number of items in the collection.
+     * @return {Number} The number of items in the collection.
+     */
+    getCount: function(){
+        return this.all.getCount();
     }
-});</pre>    
+});
+</pre>
 </body>
-</html>
\ No newline at end of file
+</html>