View Full Version : BIG MVC application

28 Oct 2011, 11:33 PM

i'm new to MVC in Javascript applications, maybe someone could help me with my problem.
I'm building a large EXTJS MVC application- atleast this is a plan. By large I mean that it will consist of many views, stores, models, business logic, and i dont want to load all stores, views, models at startup. The problem is that many views (view code) are generated dinamically on server (i know this is bad practise but anyway) and i need to load this controllers, views, stores dinamically - that is when i choose an option from let's say main app menu.

Now the question is:
Which part of code is responsible for instantiating view and placing it on apropriate place on viewport? Is this usually done in controller function init() ?
I'm thinking like this, at first I should dinamically load cotroller with all dependencies. Controller loader would automatically load all dependencies (stores, views, models) and then in controllers init() function i would instantiate views (and place it on the right place in GUI), and then call controllers function control() to setup event listenersfor that view.
Is this the right way to do it? :-?

best regards, Andrej :D

29 Oct 2011, 9:40 AM
I'm working that way.

I have a "main" controller with a setMainView method that is called by the others controller, the main controller adds the view to the viewport.

30 Oct 2011, 8:21 AM
I'm working the same way, so far so good :)

It doesn't matter if you call the "control" method before or after you create the views instances, what it really matters is that you need to be as much specific as you can with the selectors. The following code create the views on the init method, I have defined an abstract controller that calls the "setViewport" method, this method should be implemented in the subclasses:

https://github.com/crysfel/Bleextop/blob/master/js/Bleext/abstract/Controller.js#L26 (abstract controller)

Also I have overridden the control method adding the id of the window (i'm using the desktop) that it's holding the views, this way allows me to open the same app more that one time and every selector will match the right view, take a look at the following code:



1 Nov 2011, 11:38 PM
Thank you crysfel and ldonofrio for answers. I'ts always good to hear another opinion.

I have one more question though. What about clean-up of this dinamically instantiated views, stores, controllers? Is it possible to remove - delete controller and than controller destructor would take care of deleting store and views so RAM wouldn't fill up?

I know i could use card layout and than just hide unactive card and show it again when it would be needed, but i choose to delete unneded items.

best regards

2 Nov 2011, 7:27 AM