PDA

View Full Version : Sencha Touch MVC and Namespaces



DrunkenBeard
30 Aug 2011, 2:30 AM
Hi,

I'm starting a rather complex web application using Sencha Touch and having a hard time understanding how namespaces work across multiple class files. Let me start by briefly outlining the application tree :


27747





I purposely left out the lib and resources folders as they aren't relevant to the current problem. Now inside my app.js there is a simple launch function which instantiates the Viewport. Inside the Viewport I can use the app.views namespace freely, I can add classes to that namespace etc. I can also use the app.views namespace anywhere in my other files inside the "medecins" folder. All this is good and working great.

Now my problem is that I want classes inside the "medecins" folder to be under the app.views.medecins namespace (not simply app.views). How do I do that ? And how do I reference them in other files ? Is there something like a "use" statement ? I tried all kinds of things but just came to the conclusion that I'm lacking some knowledge regarding namespaces in Sencha Touch.

Any help would be appreciated. Thanks :)

DrunkenBeard
30 Aug 2011, 3:31 AM
Ok, so it seems I've found out the missing piece of information. I only needed to declare the app.views.medecins namespace using Ext.ns before using it. Now I have another little question : where is the best place to add new namespaces when you have lots of them ? Make a dedicated JS where you only declare namespaces ? Add them in app.js ? Or just add each one in the first JS that uses it ?

Thanks :)

PS : Feel free to add any information on namespaces if you think it could help.

fx-mike
30 Aug 2011, 5:26 AM
I put my extra name spaces in app.js, but I don't have many to add. Adding a namespace to the first js file that uses it seems kind of unsafe. I think you can add the same namespace to multiple files without harm, so just add the appropriate namespace to every file if you want to take that route.