PDA

View Full Version : [4.1 b1] Ext.widget() with config as first param



slemmon
16 Jan 2012, 1:29 PM
In 4.1 will the following syntax work:


Ext.widget({
xtype: 'panel'
title: 'Hello',
width: 200,
html: '<p>World!</p>',
renderTo: Ext.getBody()
});

or


Ext.create({
xclass: 'Ext.panel.Panel'
title: 'Hello',
width: 200,
html: '<p>World!</p>',
renderTo: Ext.getBody()
});

mitchellsimoens
16 Jan 2012, 8:51 PM
No, they both need a string as the first argument:


Ext.widget('panel', {...});
Ext.create('Ext.panel.Panel', {...});

slemmon
17 Jan 2012, 6:24 AM
In November Don Gryphon had mentioned that having the config be the first param was on the roadmap for 4.1. Do you know if it is still on the roadmap beyond 4.1?

http://www.slideshare.net/senchainc/ext-js-41-layouts-performance-and-api-updates

LesJ
17 Jan 2012, 6:37 AM
Instead of Ext.create or Ext.widget, use new. You'll get slightly better performance and it's easier to debug.

slemmon
17 Jan 2012, 7:13 AM
In the plugin I'm working on I'm adding a field to a grid column header. It will allow any field type component to be passed in as a config. So, if the component passed in is of type trigger or is of type textarea I'll need to be able to accommodate both.

Today I create a container and add the passed in config to the container's items array, but was hoping to employ the Ext.widget({..config..}) directly which I could do without needing the first string parameter of the xtype to be rendered.

Sadly, 'new' leaves me in the same pickle. Was when I saw Don's slideshare talking about the roadmap for 4.1 that create using 'xclass' and widget using the config alone would end up in 4.1, but looks like it might have not made it into the release after all. I'll cross my fingers for 4.2.

dongryphon
23 Jan 2012, 12:02 AM
Yes, Beta 1 does support the single-argument forms of Ext.create and Ext.widget as the original poster asked.

Of course, the original, 2 argument form are also supported.

We did optimize Ext.widget a bit as well, but all forms of dynamic creation (where the type is data) are more expensive than static creation (using "new" keyword). This is an unavoidable price when the type cannot be known otherwise, but also a price that can be avoided when it is not needed.

A good use for this idiom is to use template methods that return these config objects which include type in the data. That way a derived class can not only override and augment the configuration but also control the type of object to be created. Very powerful.

LesJ
23 Jan 2012, 3:11 AM
Don,

Please take a look at your presentation that was mentioned in this thread, page 144.

http://www.slideshare.net/senchainc/ext-js-41-layouts-performance-and-api-updates
(http://www.slideshare.net/senchainc/ext-js-41-layouts-performance-and-api-updates)
Do you support the wildcard syntax? I don't think it was supported in 4.0.


Ext.define('My.app.App', {
requires: ['My.patches.*'], // Is wildcard supported here?
...
});

slemmon
23 Jan 2012, 5:53 AM
I had trouble with * as well (haven't tried in 4.1). But, if I required My.ext.Tree and My.ext.Plugin I had to list each explicitly as My.ext.* wasn't loading the classes.

skirtle
23 Jan 2012, 8:20 AM
As I understand it using * will only work if you've included the classes in a manifest. The file pkgs/manifest.js is the manifest for the library's own classes and it gets built into the file ext.js. Without such a manifest there's no way for the loader to know what * actually means.