1. #1
    Sencha Premium Member
    Join Date
    May 2008
    Location
    Pasadena, California
    Posts
    172
    Answers
    27
    Vote Rating
    2
    NickT is on a distinguished road

      0  

    Default Answered: Ext.define xtype vs alias

    Answered: Ext.define xtype vs alias


    Hello,
    I was noticing that in the defining of Ext.dataview.List, an xtype was provided as part of the config, whereas with a field extension, like TextArea, an alias was provided...


    alias :'widget.textareafield',

    is the xtype derived from the alias for field extensions. Is there a precedence if both an alias and xtype are defined in the config. What is the best practice for defining the xtype as was done with Ext.reg in 1.1

    thanks. version 2 as with all of your code looks terrific and I am eager to get my stack converted over to it.

  2. This was done purely for performance. If we don't have to parse the string to get the xtype, it's faster. Instead of have xtype, ptype, ltype, and on and on, we have a specific xtype since it is so common and the rest use alias.

  3. #2
    Sencha User
    Join Date
    Mar 2007
    Location
    Haarlem, Netherlands
    Posts
    1,243
    Answers
    28
    Vote Rating
    9
    TommyMaintz will become famous soon enough TommyMaintz will become famous soon enough

      0  

    Default


    Hi,

    For components the preferred mechanism to define an xtype is to use the xtype: 'myxtype' syntax. It is just a convenience as it gets converted into alias: 'widget.myxtype' internally. The alias in TextArea is just an oversight. The alias property is more generic and applies to all classes. For example layouts use alias: 'layout.mylayoutname'.

  4. #3
    jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    Frederick MD, NYC, DC
    Posts
    16,353
    Answers
    102
    Vote Rating
    77
    jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all

      0  

    Default


    I use xtype too for extensions to Component.. But this is does ad some confusion.

  5. #4
    Sencha - Sencha Touch Dev Team Jamie Avins's Avatar
    Join Date
    Mar 2007
    Location
    Redwood City, California
    Posts
    3,661
    Answers
    17
    Vote Rating
    21
    Jamie Avins is a jewel in the rough Jamie Avins is a jewel in the rough Jamie Avins is a jewel in the rough Jamie Avins is a jewel in the rough

      0  

    Default


    This was done purely for performance. If we don't have to parse the string to get the xtype, it's faster. Instead of have xtype, ptype, ltype, and on and on, we have a specific xtype since it is so common and the rest use alias.

  6. #5
    jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    Frederick MD, NYC, DC
    Posts
    16,353
    Answers
    102
    Vote Rating
    77
    jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all

      0  

    Default


    Dude i agree with this change 100%. Coming from Ext 4, it's a tad confusing - that's all.

    I *really* hope this makes it way into Ext 4. Every time i do a bootcamp, I get confused looks when I start to go beyond 'xtype' into 'type, ftype, ptype', etc.

  7. #6
    Sencha - Community Support Team edspencer's Avatar
    Join Date
    Jan 2009
    Location
    Palo Alto, California
    Posts
    1,939
    Answers
    29
    Vote Rating
    7
    edspencer is a jewel in the rough edspencer is a jewel in the rough edspencer is a jewel in the rough

      0  

    Default


    ftype, ptype and the rest need to die
    Ext JS Senior Software Architect
    Personal Blog: http://edspencer.net
    Twitter: http://twitter.com/edspencer
    Github: http://github.com/edspencer

  8. #7
    Sencha User
    Join Date
    Jan 2009
    Location
    West Coast
    Posts
    37
    Vote Rating
    0
    slchorne is on a distinguished road

      0  

    Default they're 2 different operations

    they're 2 different operations


    i think mixing the use of 'xtype' and 'alias' is confusing, and (knowing how I write code) leads to ugly syntax errors. To me, 'xtype' means "Instance component of this type", but in 'Ext.define' it means "Create a new component (alias) with this name/type".

    And, if you start by writing some code with a lazy def :

    Code:
    items:[{ 
        xtype: 'button',
        width:100,
        heght:50,
    }]
    then later decide that this would be better as it's own component, a less than careful cut/paste, or rewrite would produce this:

    Code:
    Ext.define('tixButton', {
        extend: 'Ext.Button',
        xtype: 'button',
        width:100,
        heght:50,
    }]
    So you've gone either clobbered the 'button' xtype, or generated a confusing error.


    It least in Ext 3, you have the clear distinction by using 'Ext.reg' to create the alias. Perhaps sticking to just 'alias' or creating a new config item like 'regXtype' would make more sense ?

  9. #8
    Sencha User
    Join Date
    Nov 2011
    Posts
    16
    Answers
    1
    Vote Rating
    0
    michaelreneer is on a distinguished road

      0  

    Default


    I am still a bit confused. When I define a component, lets say the Ext.Container below, should I assign an alias or an xtype to it? The container will have two items, a toolbar and a list. If I want the controller to be able to reference these sub views: should I assign aliases to them as well or should I give them id's?

    Code:
    Ext.define('app.view.thing.List', {
    	config: {
    		layout: 'fit'
    	},
    	extend: 'Ext.Container',
    	
    	initComponent: function() {
    		var toolbar = Ext.create('Ext.Toolbar', {
    			docked: 'top'
    		});
    		
    		var list = Ext.create('Ext.List', {
    			itemTpl: '<p>item</p>',
    			store: 'Things'
    		});
    		
    		this.add([
    			toolbar,
    			list
    		]);
    		
    		this.callParent();
    	}
    });

  10. #9
    Sencha User castitas's Avatar
    Join Date
    Sep 2011
    Location
    US
    Posts
    116
    Answers
    3
    Vote Rating
    2
    castitas is on a distinguished road

      0  

    Default


    It's been a while, but I figured I'd tie up the loose question at the end.

    When you define a component, use an alias.
    When you create an instance of a component (one that will be rendered) use an id.

    sidenote: You don't have to give them id's to reference objects defined in items, as you can use .down(' ') to get to them.

    The ext standard for the vars in the code above should probably be placed in a config object under tbar/dockedItems and items.
    word