PDA

View Full Version : Ext.extend Not run



siuka
24 Jun 2009, 11:53 PM
Hello,

I am developing a sub-set components of ExtJS, and I used the 'yuicompressor-2.4.2.jar' to concat and compress those js files into a xxx-all.js.

And my problem is that sometime these classes cannot load into the browser. When this problem happened, I found there isn't any DOM object of my classes showing in the firebug's DOM panel. And the browser will throw xxx is undefined which xxx is the name of my classes.

Today I added some log into Ext.extend, and found that the return function of Ext.extend didn't run ...

Please help.

Thanks.

hendricd
25 Jun 2009, 1:55 PM
@siuka - Posting an example of how you are using Ext.extend might help.

No example == just guessing.

Are you including your new classes after the Ext classes in your build sequence?

siuka
25 Jun 2009, 7:57 PM
Thanks hendricd.

My program is very simple, just like the example from FAQ or help.




// create namespace 'App.btn'
Ext.ns('App.btn');

App.Button = Ext.extend(Ext.Button, {
start: 0
, constructor: function(config) {
// private variables
var myHandler = null;
// set the extra css class name for button
config.cls = config.cls==null?'x-btn-general':config.cls;
config.handlerFn = config.handler==null?null:config.handler;
config.handler = null;
if ( config.href != null ) {
config.beforeHrefFn = config.handlerFn;
config.handlerFn = function(btn) {
var result = true;
if ( btn.beforeHrefFn != null ) {
result = btn.beforeHrefFn(btn);
result = result==null?true:result;
}
if ( result ) {
window.location.href = btn.href;
}
}
}
if ( config.type != null ) {
if ( config.type.toLowerCase() == 'submit'
|| config.type.toLowerCase() == 'reset' ) {
myHandler = function(btn) {
var result = true;
var form = null;
form = App.Util.findRootFormCt(btn);
if ( form != null ) {
var name = null;
var value = null;
if ( btn.name != null && btn.value == null ) {
name = btn.name;
value = "";
} else if ( btn.name != null && btn.value != null ) {
name = btn.name;
value = btn.value;
}
if ( name != null && value != null ) {
form.add({xtype: 'hidden', id: name, name: name, value: value});
form.doLayout();
}
}
if ( btn.handlerFn != null ) {
result = btn.handlerFn(btn, form);
}
result = result==null?true:result;
if ( result ) {
if ( form != null ) {
if ( btn.type.toLowerCase() == 'submit' ) {
form.submit();
} else {
form.reset();
}
}
}
}
}
} else {
myHandler = config.handlerFn;
}
config.handler = myHandler;

// default config options here
Ext.apply(this, {
minWidth: config.minWidth==null?80:config.minWidth,
end: 0
});

// And Call the superclass to preserve baseclass functionality
App.Button.superclass.constructor.apply(this, arguments);

}
});


// create namespace 'App.data'
Ext.ns('App.data');

// doing the other part ...

And I found that Ext.ns('App.btn'); is executed, but App.Button = Ext.extend(Ext.Button, { ... and Ext.ns('App.data'); not without any error. Therefore I don't know what is the root cause of my code ...

And this happened randomly ...

danh2000
25 Jun 2009, 9:25 PM
..


Hi,

You declare an App.btn namespace but never use it.

The Ext.extend call works perfectly - it creates an App.Button class that extends Ext.Button.

You can test that the extend part works by doing something like:


new App.Button({
renderTo: document.body
});

I think your post is too cryptic - maybe you should put an online example together and post the URL with instructions on how to reproduce the error.

siuka
25 Jun 2009, 10:24 PM
Hi hendricd,

My code is in two external js files which after the ext-base.js and ext-all.js.



Hi danh2000,

Thanks for your reply.

However this happened randomly, so that I cannot provide the way to reproduce it ...
And I do not want to make this so cryptic too, but I really don't know where the problem is ... so I cannot describe it very well ... sorry. I have been tried to fix this for two months already ... :((

All worked well for local testing, but it may happen under running with the server.

Besides, I can provide more information about my working environment.
I am using java (springframework) and the server is websphere. The IDE tool is ibm's RAD.


Sorry for any inconvenience and thanks for the help.

hendricd
26 Jun 2009, 3:20 AM
@suika --Assuming this only happens after YUI compression, try adding:

--preserve-strings and --preserve-semi to your command line options, and see if the problem persists.

siuka
29 Jun 2009, 3:32 AM
Hi hendricd,

Thanks for your reply.
I found that this is not the error from YUI compression, because I am using the debug version which is a js file with all content without any compression.

I find that there is an infinite loop in Ext.extend.
I try to add the print out after each line in the function Ext.extend and finally I got this screen cap. (please refer to the attachment or below external image)
http://img34.imageshack.us/img34/5574/extextendlog.jpg)

Here is log added version of Ext.extend.


//Ext.override(Ext, {
// extend : function(){
Ext.extend = function(){
// inline overrides

try{if(typeof(isDebug)!="undefined"&&isDebug){console.debug("Component initiation - Ext.extend - Start");}}catch(el){}

var io = function(o){
for(var m in o){
this[m] = o[m];
}
};

try{if(typeof(isDebug)!="undefined"&&isDebug){console.debug("Component initiation - Ext.extend - Debug ...");}}catch(el){}

var oc = Object.prototype.constructor;

return function(sb, sp, overrides){

try{if(typeof(isDebug)!="undefined"&&isDebug){console.debug("Component initiation - Ext.extend - Debug - 0 - " + (typeof(sb)));}}catch(el){}
//var extabc=false;try{if(typeof(isDebug)!="undefined"&&isDebug){if(sb.toSource().indexOf("function () {sp.apply(this, arguments);}")>=0){extabc=true;console.debug("Component initiation - Ext.extend - Debug - 1");}}}catch(el){}extabc=true;

if(typeof sp == 'object'){
overrides = sp;
sp = sb;
sb = overrides.constructor != oc ? overrides.constructor : function(){sp.apply(this, arguments);};
}

try{if(typeof(isDebug)!="undefined"&&isDebug){if(typeof(isButton)!="undefined"&&isButton){console.debug("Component initiation - Ext.extend - Debug - 2");}}}catch(el){}

var F = function(){}, sbp, spp = sp.prototype;

try{if(typeof(isDebug)!="undefined"&&isDebug){if(typeof(isButton)!="undefined"&&isButton){console.debug("Component initiation - Ext.extend - Debug - 3");}}}catch(el){}

F.prototype = spp;

try{if(typeof(isDebug)!="undefined"&&isDebug){if(typeof(isButton)!="undefined"&&isButton){console.debug("Component initiation - Ext.extend - Debug - 4");}}}catch(el){}

sbp = sb.prototype = new F();

try{if(typeof(isDebug)!="undefined"&&isDebug){if(typeof(isButton)!="undefined"&&isButton){console.debug("Component initiation - Ext.extend - Debug - 5");}}}catch(el){}

sbp.constructor=sb;

try{if(typeof(isDebug)!="undefined"&&isDebug){if(typeof(isButton)!="undefined"&&isButton){console.debug("Component initiation - Ext.extend - Debug - 6");}}}catch(el){}

sb.superclass=spp;

try{if(typeof(isDebug)!="undefined"&&isDebug){if(typeof(isButton)!="undefined"&&isButton){console.debug("Component initiation - Ext.extend - Debug - 7");}}}catch(el){}

if(spp.constructor == oc){
spp.constructor=sp;
}

try{if(typeof(isDebug)!="undefined"&&isDebug){if(typeof(isButton)!="undefined"&&isButton){console.debug("Component initiation - Ext.extend - Debug - 8");}}}catch(el){}

sb.override = function(o){
Ext.override(sb, o);
};

try{if(typeof(isDebug)!="undefined"&&isDebug){if(typeof(isButton)!="undefined"&&isButton){console.debug("Component initiation - Ext.extend - Debug - 9");}}}catch(el){}

sbp.override = io;

try{if(typeof(isDebug)!="undefined"&&isDebug){if(typeof(isButton)!="undefined"&&isButton){console.debug("Component initiation - Ext.extend - Debug - 10");}}}catch(el){}

Ext.override(sb, overrides);

try{if(typeof(isDebug)!="undefined"&&isDebug){if(typeof(isButton)!="undefined"&&isButton){console.debug("Component initiation - Ext.extend - Debug - 11");}}}catch(el){}

sb.extend = function(o){Ext.extend(sb, o);};

try{if(typeof(isDebug)!="undefined"&&isDebug){if(typeof(isButton)!="undefined"&&isButton){console.debug("Component initiation - Ext.extend - Debug - 12");}}}catch(el){}

return sb;
};
}();
//});
This is very strange ...

Please help ...