Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExtJS 4 - questions about MVC architecture, using MVC for component development

I have few Extjs 4 MVC architecture questions and would be very grateful for some hints or examples.

  1. How controllers are connected with their views? What is the pattern for the controller having a reference to its view?

  2. Are controllers supposed to be global for the application instance? I have seen only examples showing the controllers being loaded by the application instance, but I have never seen a controller being a part of some sub-component. Does it mean that MVC does not apply to component classes? Example: I'd like to build a list search component that consists of a grid, a search criteria panel and few more controls/menus. MVC would be quite useful for implementing the internal logic of that control, but extjs API suggests that this is not a supported scenario.

  3. There's a nice dynamic loading feature in Extjs 4 (Ext.require). But is it supposed to work somehow with the MVC architecture? Is dynamic loading of views and controllers supported? As in previous question, I have seen only examples where all controllers, models and views are loaded upfront on application startup. I'm thinking about loading a view on user's action and the name of that view is known only after the user completes the action - how to go about loading that view, what about its controller?

best regards RG

like image 804
nightwatch Avatar asked Jan 18 '23 05:01

nightwatch


1 Answers

  • I recommend the Supervising Controller pattern. Essentially, the view has no logic, except for simple data binding (think comboboxes and grids), and all the event handling is in the controller (example: user clicks a button to refresh a calculation). The model handles all data logic (example: calculating the monthly payment on a loan). A controller can load a model into a view using form.loadRecord() and save form values to a model using form.updateRecord().

  • Controllers should have no state: no user-defined properties, just event handlers. This way, a controller can handle multiple view instances at the same time. You will need some trickery to get a reference to the view (via the first parameter), but I haven't had any problems.

  • You can load all of your controllers at startup. Just make sure you concatenate and minimize your files.

like image 200
Neil McGuigan Avatar answered Feb 08 '23 16:02

Neil McGuigan