View Full Version : xtypes for plugins

28 Dec 2008, 6:59 AM
I find it useful and somewhat interesting to implement xtypes for plugins. Here it is:
(This isn't really a plugin since this class isn't plugged into a component)


Ext.ux.component.patches.ComponentPluginsXTypesPatch = function(){
return {
onInitPlugin : function(p){
var isXtype = ( p.xtype && typeof p.init != 'function' );
var i = this.plugins.indexOf(p);
p = Ext.ComponentMgr.create(p);
this.plugins[i] = p.init(this);

return !isXtype; //if isXtype, return false (i.e, do not use initPlugin)

install : function(){
Ext.Component.prototype.initPlugin = Ext.Component.prototype.initPlugin.createInterceptor(this.onInitPlugin);

//now you can:

//sample plugin for a grid. let's say, saki's Ext.ux.grid.Search

Ext.ux.grid.Search = function(){
Ext.extend(Ext.ux.grid.Search, Ext.util.Observable, {

//at the end:
Ext.reg('grid_search_by_saki', Ext.ux.grid.Search);

//using the plugin:
var grid = new Ext.grid.GridPanel({
plugins : [{
xtype : 'grid_search_by_saki', <OTHER _CONFIG_OPTIONS>

Why do this?
1.) If you are retrieving your object's definiton asynchronously, then you can now include plugins in the definition. Like this:

var loader = new ComponentLoaderClass({
url : '...'

loader.on("load", function(def){
//assume that def is a json that contains the plugin's defintion with xtype's
var grid = new Ext.grid.GridPanel(def.gridDefinition)

2.) saves me some typing (:D)
Some might find this useless, but to me xtypes for plugins, or for any class whose definition at instantiation can be pre-defined and loaded from the server, is a must.

28 Dec 2008, 7:50 AM

ptypes are in Ext3

Search "ptype". You may be better served to bump the existing threads for this subject.

28 Dec 2008, 8:10 AM
Thanks again for the inputs.

Again, I find 'ptypes' needless. All classes are components; they tend to work together. So why introduce another type? In fact a class, in itself, is a type. 'xtypes' are simply a string representation.
To quote the docs: "a mnemonic code known as the Component's xtype"
Why create another?
Jack is of course on that post technically correct. Note that he used "C"omponent. Meaning, as the Ext framework currentlywould views plugins. Who knows that someday, Component might descend another class.

I do not know if ptypes are indeed in 3.0, as I do not have access to SVN. Apparently, Jack simply provided an override, or abstracted a method, so that it could be easily overridden.

Anyway, I am not forcing anyone to adapt my concepts. I am merely pointing the fact (with reasons from this thread: http://extjs.com/forum/showthread.php?p=267007#post267007) that ptypes, stypes, ztypes, or whatever is conceivable by man, are needless. xtypes suffices.

(p.s. Humans had for centuries tried to determine what exactly makes a man unique. Let us not make that the case for Ext :D)

28 Dec 2008, 11:06 AM
I'm merely trying to point you to the relevant threads and info.

You appear to have some following already in the thread I pointed you towards, so to me the discussion should be continued there, not here. Evan and Jack are already subscribing to that thread.

Evan brought up ptypes in that thread. Aaron flushed out registering plugins via ComponentMgr in another thread.

28 Dec 2008, 6:49 PM
Evan brought up ptypes in that thread. Aaron flushed out registering plugins via ComponentMgr in another thread.

I will reply, not in the hope of starting a new discussion.

When Evan brought that up, I don't think he was dead serious (just because of the smiley following his remark). He was merely playing on an idea.

I found this thread : https://extjs.com/forum/showthread.php?p=115554
Aaron's statement seemed NOT TO IMPLY "flushing out" the idea of "xtypes for everything". He merely pointed out that it could require a lot of changes.

28 Dec 2008, 7:43 PM
Well, someone thought it serious enough that it is in the Ext 3 code base. Of course, it's alpha code, so it could always change.

28 Dec 2008, 10:10 PM
Yep. I hope that "seriousness" dies out. I mean, largely it is up to the community to decide. Obviously, I will be in the camp which says "'xtypes' for everything."