PDA

View Full Version : Custom namespace that worked in ext2.2 breaks in ext3.0



cnesbit
11 Nov 2009, 6:15 AM
I am trying to make the transition from ext2.2 to ext3.0 in my application (thanks to helpful info at http://www.extjs.com/products/extjs/CHANGES_ext-3.0.1.html ) but I ran into a pretty big wall that I can't seem to get past. It may just be that I don't understand namespaces very well, or that I'm not actually using a namespace when I think I am? help would be appreciated.

In my js file where I define site-wide variables and settings I have the following code:


Ext.namespace('InfoDirect', 'InfoDirect.Home'); //used for a namespace of InfoDirect.Home elsewhere on the site, as well as (I think) InfoDirect
...
InfoDirect.studentNames = undefined; //will be an array of students assigned to the current user
InfoDirect.currentStudentID = undefined; //will be the currently selected student
InfoDirect.userRole = undefined; //will be the user's role (teacher, parent, ...)

later on in my site, I call a function that loads some of those settings using the following code. I walked the code in firebug to verify that my "success" function is being run,


if (InfoDirect.studentNames == undefined) {
Ext.Ajax.request({
url: 'data.php',
async : false,
params: {command: 'getStudentNames'},
success: function ( result, request ) {
InfoDirect.studentNames = Ext.util.JSON.decode(result.responseText).studentNames;
}
});
}
but my site doesn't seem to recognize my "global" InfoDirect.studentNames variable as anything but undefined. oddly enough, if I break while my site is in the process of loading and spit InfoDirect.StudentNames out to firebug, it does return my students correctly.

I'm a bit confused, to say the least. Especially since the code is pretty much error proof in Ext2.2 but is acting like it is ignoring my code in Ext3.0 (even though I can watch it get executed). The same problem is happening to all my InfoDirect.* variables...

Help! :)
cnesbit

BitPoet
11 Nov 2009, 6:39 AM
There is no async parameter for an Ext.Ajax.request call, so if you're expecting the call to run synchronuously and block script execution, you're getting bitten by an old error in the 2.2.x code that was masked by the app's delay and only hits now due to rearranged code or improved ext3 performance.

cnesbit
11 Nov 2009, 6:46 AM
There is no async parameter for an Ext.Ajax.request call, so if you're expecting the call to run synchronuously and block script execution, you're getting bitten by an old error in the 2.2.x code that was masked by the app's delay and only hits now due to rearranged code or improved ext3 performance.

so, the async property (that did work in ext2.2) no longer works in ext3.0? Doh!

Note, that I understand why synchronous server calls are generally frowned upon in ajax. But for our specific needs, and when done in a minimalist fashion, it accomplishes our goals for this site. So please understand I am not here to open that whole can of worms.

I just need a working solution that can be applied without revamping the whole (rather large) site. like maybe a custom override for the ext.lib.ajax.request({async}) property that allows me to accomplish the same goal?

-cnesbit

hendricd
11 Nov 2009, 6:51 AM
@cnesbit -- Just add the ext-basex Adapter extension (see my sig below) into your page to bring async:false back to life until you figure things out. ;)

cnesbit
11 Nov 2009, 6:56 AM
@cnesbit -- Just add the ext-basex Adapter extension (see my sig below) into your page to bring async:false back to life until you figure things out. ;)

ahah! So that's what the ext-basex-min.js file was for, in our site. I had commented that out in effort to get ext3.0 running error free. If I simply place that file back into my site as it originally was, though, I get the following error in firebug, and the site stops loading:

this.headers is undefined
ext-basex-min.js (line 1) //->there's only 1 line, and it has several occurences of "this.headers"...

hendricd
11 Nov 2009, 6:59 AM
ahah! So that's what the ext-basex-min.js file was for, in our site. I had commented that out in effort to get ext3.0 running error free. If I simply place that file back into my site as it originally was, though, I get the following error in firebug, and the site stops loading:

this.headers is undefined
ext-basex-min.js (line 1) //->there's only 1 line, and it has several occurences of "this.headers"...

Much has changed in 3.0, so you'll need to use the latest version of ext-basex as well.

Animal
11 Nov 2009, 7:04 AM
Why don't you just set the success config of the request to be the function which continues processing, and uses the returned value?

That way, you won't block the entire browser for the duration of the Ajax request.

cnesbit
11 Nov 2009, 7:04 AM
Much has changed in 3.0, so you'll need to use the latest version of ext-basex as well.

heh, funny how things just magically work when done properly. :D Thanks a bunch for your help guys!

-cnesbit

hendricd
11 Nov 2009, 7:08 AM
Why don't you just set the success config of the request to be the function which continues processing, and uses the returned value?

That way, you won't block the entire browser for the duration of the Ajax request.

@cnesbit -- Animal raises a good point here. Your transition to a new release is a good opportunity to rethink your App's startup strategy.

Get asynchronous ! ;)

cnesbit
11 Nov 2009, 7:15 AM
Why don't you just set the success config of the request to be the function which continues processing, and uses the returned value?

That way, you won't block the entire browser for the duration of the Ajax request.

I've got several pages in a card layout which need the studentNames variable to be loaded before the pages can be built/process/rendered/anything. But the whole site loads all at once. The only proactical way I see of accomplishing this is to have a single, minimalist, synchronous call (typcially taking 800ms) load that variable prior to loading the rest of the site.

But, as all reasonable developers, I know there's always 500 ways to skin the same cat and some ways can be better than others. If you care to elaborate on your suggestion, I am open to ideas other than my own, though I explained earlier that
I am not here to open that whole [synchronous] can of worms. I just need a working solution..

Animal
11 Nov 2009, 7:21 AM
All that code which you are performing to do all that setup?

Put it in a function.

Use that as the success handler.

cnesbit
11 Nov 2009, 7:36 AM
that is a very good idea.

all that "load" code is farther down the same function, so it makes sense how I could do that. that would work if I was calling this function only once. But, the catch is ;), this function gets called by (most) every page in the card layout, so I'd have to do a bit of code reorganization to do it "properly".

It is a great idea, however, and has got me thinking. perhaps next time I have a rainy day, I will look further into organizing this code the "correct" way. but for today, that's more work than I have time for.

Thanks to all for your insightful help! I appreciate the ideas, suggestions, and guidance this forum offers. Extjs is such a powerful tool for sure!

-cnesbit