PDA

View Full Version : Application Architecture



Dave.Sanders
18 Jun 2009, 12:59 PM
This question is mainly for Saki, but I figured I'd post it publicly in case someone can beat him to the answer. :)

On this tutorial: http://extjs.com/learn/Tutorial:Application_Layout_for_Beginners I understand why someone would use this pattern. But I'm struggling to easily extend the "app" function that I create to include Ext.util.Observable. I'm trying to easily add in the event handling model into my "app" object.

I've tried to do an Ext.extend(mynamespace.app, Ext.util.Observable); after the declaration of the mynamespace.app, but it didn't seem to work. I also tried add it into the init function, but again, no dice.

What am I missing? Or does this method of setting up your main application function not work with extend? Another idea I had would be to just add a "var e = new Ext.util.Observable();" to my app object and just create pass through functions for AddEvents, FireEvent, and so on. But I'm guessing there's an easier way, or I shouldn't be doing it this way.

Thanks
Dave

ry.extjs
18 Jun 2009, 1:57 PM
here's what i did: http://extjs.com/forum/showthread.php?p=310928#post310928

as always, there are many ways to skin a cat.

Animal
18 Jun 2009, 9:44 PM
Why create an application Class? You will never instantiate several.

It's a natural singleton.

So



com.acme.Application = Ext.apply(new Ext.util.Observable, (function(){
// private vars
// private functions

return {
init: function() {
this.addEvents('myevent1', 'myevent2'...);
// other initialization... create Viewport etc
},
otherPublicMethod: function() {
...
}
};
}()));


It's an Observable with an extra set of properties (returned from a closure in order to capture some private members) applied to it.

Simples.

jay@moduscreate.com
19 Jun 2009, 3:34 AM
Nige, this question was for saki 8-|

Dave.Sanders
19 Jun 2009, 9:08 AM
That makes sense animal, using the apply instead of trying to extend a class. Thanks!