PDA

View Full Version : ExtJS Code Organisation - A quick question - Open discussion



Flukey
7 May 2010, 1:44 AM
Hi all,

I'm aware this has probably been discussed before, however, i'm at a bit of a loss at the moment about seperating my js files.

At the moment, i'm thinking of doing the following:


application.js = This will build the view and register the namespaces
actions.js = This will store all of my actions (i.e. clicking on a navigation menu item). It will be namespaced as Ext.myapp.actions
stores.js = This is where I will put all of my data stores configuration etc. Namespaced as Ext.myapp.stores
controls.js = This is where I will put all of my controls (i.e. forms, datagrids). Namespaced as Ext.myapp.controls



Is this a good or a bad approach?

criticism is more than welcome. I like to learn new ways of doings things! How have you seperated your code?

Thanks very much!

Condor
7 May 2010, 2:24 AM
Correctly applied MVC pattern, but I would use actions, stores and controls directories and put every actionset, store and control in their own .js file within these directories.

Flukey
7 May 2010, 3:37 AM
Correctly applied MVC pattern, but I would use actions, stores and controls directories and put every actionset, store and control in their own .js file within these directories.

Excellent idea. Thanks very much.

Animal
7 May 2010, 3:52 AM
And you include them separately during development, but concatenate all Javascript into one file, and minify it, and include just that sing;e Javascript file for release of course.

Flukey
7 May 2010, 4:19 AM
And you include them separately during development, but concatenate all Javascript into one file, and minify it, and include just that sing;e Javascript file for release of course.

Indeed. :-)

So, let me just make sure i've got this right.

I have seperate directories for actions, controls and stores. Check.

So let me make an example:

I have an action:


Ext.myapp.actions.submitJob

This will have my event listener etc.

And in my control, I'll have:


Ext.myapp.control.submitJob

This will have the code for the form, buttons etc.

And then of course for my store i'll have:


Ext.myapp.stores.submitJob

which will have the store that my action will be sending data to.

Would you agree with this?

Cheers guys.