Skip to content

Instantly share code, notes, and snippets.

@gorkunov
Created August 8, 2011 12:51
Show Gist options
  • Save gorkunov/1131694 to your computer and use it in GitHub Desktop.
Save gorkunov/1131694 to your computer and use it in GitHub Desktop.
defining preprocessors for extjs4
//add set default xtype preprocessor
Ext.Class.registerPreprocessor('default_xtype', function(cls, data) {
var className = data.$className;
var re = new RegExp(/^cl.view./);
if (re.test(className) && !data.alias) {
data.alias = 'widget.' + className.replace(re, '').replace(/\./g, '_').toLowerCase();
/*
* Overide default initComponent for defining component config by cloning
* this section from component class body (componentConfig property).
* WARNING: you can define component configuration in class body but this configuration
* will be store in prototype class and each instance of this class
* manipulate of this data from prototype. This behavior generate many
* bugs with recreating components and etc. So use componentConfig.
*
*/
var initComponentFn = data.initComponent;
data.initComponent = function() {
var me = this,
config = Ext.clone(me.componentConfig);
if(config) {
Ext.apply(me, Ext.apply(me.initialConfig, config));
}
if(initComponentFn) {
initComponentFn.apply(me, arguments);
} else {
me.callParent(arguments);
}
};
}
}, true);
Ext.Class.defaultPreprocessors.push('default_xtype');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment