-
10 Apr 2012 12:08 PM #1
class vs xtype ??
class vs xtype ??
Hi,
I know that you can use the properties xclass or xtype in order to instantiate a class in Sencha 2.x but actually I wanna know the differences between them, or even better, which is the best way (performance) to instantiate a class in Sencha 2x ?
Thanks in advance,
Germán.
-
10 Apr 2012 12:45 PM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,656
- Vote Rating
- 435
Code:{ xtype : 'something' }There is technically no difference between them. xclass can be used for things that aren't components.Code:{ xclass : 'MyApp.util.Foo' }Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
11 Apr 2012 4:35 AM #3
-
11 Apr 2012 4:59 AM #4Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,656
- Vote Rating
- 435
alias just defines an xtype for components. It's the type of alias and the name <type>.<name>
So 'widget.cmpname' is saying that the type of alias is a widget and the name is cmpname. For the widget, the name is also the xtype.Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
11 Apr 2012 5:39 AM #5
Tanks Mitchell for your time and quick responses!!!
Ok, I'm not clear now about the difference between use widgets or just xtypes.
When I define a component, I can useor justCode:alias: 'widget.mypanel'
.Code:xtype: 'mypanel'
Then I can use:in both cases. Correct?Code:{xtype: 'mypanel'}
Then, I've seen a code sample at API where it says that widgets allows to use the following:
So, what's the real difference between those options, and when it should be used? Is there any difference in performance? Can I just use xtype always to define my custom components, rather to use alias and widgets? Which is the advantage of alias and widgets?Code:Ext.define('MyApp.CoolPanel',{ extend:'Ext.panel.Panel', alias:['widget.coolpanel'], title:'Yeah!'}); // Using Ext.create Ext.widget('widget.coolpanel'); // Using the shorthand for widgets and in xtypes Ext.widget('panel',{ items:[ {xtype:'coolpanel', html:'Foo'}, {xtype:'coolpanel', html:'Bar'} ] });
Thanks again for your help!
-
11 Apr 2012 5:59 AM #6Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,656
- Vote Rating
- 435
You alias vs xtype will result the same thing.
If you use
That component will only be created when needed (lazy instantiation).Code:{ xtype : 'mypanel' }
If you use
That component will be created right away (direct instantiation).Code:Ext.widget('mypanel');
The benefit of lazy instantiation is you have a small object in memory until it's needed then it will be created into a full blown component. Down side is you don't have access to methods and such on that until it's created into a component, this is very rarely come upon.Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
11 Apr 2012 12:05 PM #7
Great question, I was struggling too
Great question, I was struggling too
I guess what might help me:
Is some informational/overview page which lets me know what are components, and any other high level definitions I should know.
When and why I should use:
xclass, xtype, alias, id, etc.
How should I access these objects ? Ext.getCmp ? I think I have experimented with these, and it is mind boggling to me right now when to use one verses another.
Is there a webpage with all these answers. I guess it isn't clear to me which is which. It would be nice to get the 50000 ft. view of all these concepts.
thanks for your help.
-
11 Apr 2012 12:14 PM #8Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,656
- Vote Rating
- 435
I would never use id, it will get you into trouble fast without you knowing it's coming (collisions). ComponentQuery is a much more robust and flexible solution to resolve components and it uses xtype and properties to resolve it:
example:
That would get a list that has a property foo that is set to 'bar' and is a child of a panel.Code:panel list[foo=bar]
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
17 Apr 2012 6:05 AM #9
-
17 Apr 2012 6:20 AM #10Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,656
- Vote Rating
- 435
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.


Reply With Quote