Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / docs / source / ComponentManager.html
1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-ComponentManager'>/**
2 </span> * @class Ext.ComponentManager
3  * @extends Ext.AbstractManager
4  * &lt;p&gt;Provides a registry of all Components (instances of {@link Ext.Component} or any subclass
5  * thereof) on a page so that they can be easily accessed by {@link Ext.Component component}
6  * {@link Ext.Component#id id} (see {@link #get}, or the convenience method {@link Ext#getCmp Ext.getCmp}).&lt;/p&gt;
7  * &lt;p&gt;This object also provides a registry of available Component &lt;i&gt;classes&lt;/i&gt;
8  * indexed by a mnemonic code known as the Component's {@link Ext.Component#xtype xtype}.
9  * The &lt;code&gt;xtype&lt;/code&gt; provides a way to avoid instantiating child Components
10  * when creating a full, nested config object for a complete Ext page.&lt;/p&gt;
11  * &lt;p&gt;A child Component may be specified simply as a &lt;i&gt;config object&lt;/i&gt;
12  * as long as the correct &lt;code&gt;{@link Ext.Component#xtype xtype}&lt;/code&gt; is specified so that if and when the Component
13  * needs rendering, the correct type can be looked up for lazy instantiation.&lt;/p&gt;
14  * &lt;p&gt;For a list of all available &lt;code&gt;{@link Ext.Component#xtype xtypes}&lt;/code&gt;, see {@link Ext.Component}.&lt;/p&gt;
15  * @singleton
16  */
17 Ext.define('Ext.ComponentManager', {
18     extend: 'Ext.AbstractManager',
19     alternateClassName: 'Ext.ComponentMgr',
20     
21     singleton: true,
22     
23     typeName: 'xtype',
24     
25 <span id='Ext-ComponentManager-method-create'>    /**
26 </span>     * Creates a new Component from the specified config object using the
27      * config object's xtype to determine the class to instantiate.
28      * @param {Object} config A configuration object for the Component you wish to create.
29      * @param {Constructor} defaultType The constructor to provide the default Component type if
30      * the config object does not contain a &lt;code&gt;xtype&lt;/code&gt;. (Optional if the config contains a &lt;code&gt;xtype&lt;/code&gt;).
31      * @return {Ext.Component} The newly instantiated Component.
32      */
33     create: function(component, defaultType){
34         if (component instanceof Ext.AbstractComponent) {
35             return component;
36         }
37         else if (Ext.isString(component)) {
38             return Ext.createByAlias('widget.' + component);
39         }
40         else {
41             var type = component.xtype || defaultType,
42                 config = component;
43             
44             return Ext.createByAlias('widget.' + type, config);
45         }
46     },
47
48     registerType: function(type, cls) {
49         this.types[type] = cls;
50         cls[this.typeName] = type;
51         cls.prototype[this.typeName] = type;
52     }
53 });</pre></pre></body></html>