ComponentManager.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * @class Ext.ComponentManager
  3. * <p>Provides a registry of all Components (instances of {@link Ext.Component} or any subclass
  4. * thereof) on a page so that they can be easily accessed by {@link Ext.Component component}
  5. * {@link Ext.Component#id id} (see {@link #get}, or the convenience method {@link Ext#getCmp Ext.getCmp}).</p>
  6. * <p>This object also provides a registry of available Component <i>classes</i>
  7. * indexed by a mnemonic code known as the Component's {@link Ext.Component#xtype xtype}.
  8. * The <code>xtype</code> provides a way to avoid instantiating child Components
  9. * when creating a full, nested config object for a complete Ext page.</p>
  10. * <p>A child Component may be specified simply as a <i>config object</i>
  11. * as long as the correct <code>{@link Ext.Component#xtype xtype}</code> is specified so that if and when the Component
  12. * needs rendering, the correct type can be looked up for lazy instantiation.</p>
  13. * <p>For a list of all available <code>{@link Ext.Component#xtype xtypes}</code>, see {@link Ext.Component}.</p>
  14. * @singleton
  15. */
  16. Ext.define('Ext.ComponentManager', {
  17. extend: 'Ext.AbstractManager',
  18. alternateClassName: 'Ext.ComponentMgr',
  19. singleton: true,
  20. typeName: 'xtype',
  21. /**
  22. * Creates a new Component from the specified config object using the
  23. * config object's xtype to determine the class to instantiate.
  24. * @param {Object} config A configuration object for the Component you wish to create.
  25. * @param {String} defaultType (optional) The xtype to use if the config object does not
  26. * contain a <code>xtype</code>. (Optional if the config contains a <code>xtype</code>).
  27. * @return {Ext.Component} The newly instantiated Component.
  28. */
  29. create: function(component, defaultType){
  30. if (typeof component == 'string') {
  31. return Ext.widget(component);
  32. }
  33. if (component.isComponent) {
  34. return component;
  35. }
  36. return Ext.widget(component.xtype || defaultType, component);
  37. },
  38. registerType: function(type, cls) {
  39. this.types[type] = cls;
  40. cls[this.typeName] = type;
  41. cls.prototype[this.typeName] = type;
  42. }
  43. });