Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a standard design pattern for ExtJS

We use ExtJS 3.x pretty heavily within our flagship application. Our application's admin area is split into the different modules that we offer. Each module, and subsequently each page for the different CRUD actions of the module have their own .js file to handle the functionality.

When we started, we were just throwing all of our code into Ext.onReady() and not really worrying about the global namespace (hey... we never really thought of ourselves as javascript developers). After getting the hang of ExtJS, I moved to using the singleton pattern and calling the init method from Ext.onReady() like so.

var newModule = {
    propertyOne: 'asfd',
    propertyTwo: 'asdf',
    init: function() {
        // set up
    }
};

Ext.onReady(function() {
    newModule.init();
});

Is this a correct use of the javascript singleton pattern and are there any patterns that fit ExtJS better than singleton, like say maybe the Module Pattern?

I've been using this guide as a starting point to learning design patterns in Javascript.

like image 476
Brandon Cordell Avatar asked Oct 24 '22 02:10

Brandon Cordell


2 Answers

We eventually decided to upgrade to ExtJS and it seems with the new MVC architecture in place the best way to design your ExtJS software is using Ext.application()

You can read about it here.

like image 160
Brandon Cordell Avatar answered Oct 27 '22 09:10

Brandon Cordell


You can look here for example of creating own modules, file Module.js. We used this pattern for our own application and hadn't problem with it.

Ext.app.Module = function(config){
    Ext.apply(this, config);
    Ext.app.Module.superclass.constructor.call(this);
    this.init();
}

Ext.extend(Ext.app.Module, Ext.util.Observable, {
     init : Ext.emptyFn
});
like image 42
Baidaly Avatar answered Oct 27 '22 09:10

Baidaly