I have few Extjs 4 MVC architecture questions and would be very grateful for some hints or examples.
How controllers are connected with their views? What is the pattern for the controller having a reference to its view?
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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With