-
28 Apr 2011 1:42 AM #1
Advanced MVC - Best Practices
Advanced MVC - Best Practices
Hi team and community,
since i am going to talk about the application pattern and mvc at the Sourc{ SenchaDevs conference, i would like to make sure i am aiming into the right direction. My main problem is, that the documentation is still not at the level where i would need to have it right now and that the examples are quite simple: we always have 1 model combined with 1 controller and 1 view.
1) Usecase: Multiple Instances of a view
Lets say, we build a forums-app with multiple subforums. I would like to build 1 Model, 1 Controller (for all views), n instances of the view, n instances of the store. Since the controller is set up like:
i guess it is mandatory to build 1 instance for each view as well, leading to:Code:Ext.define('AM.controller.Users', { extend: 'Ext.app.Controller', stores: ['Users'], ... });
1 Model, n controllers, n stores, n views
2) Usecase: Multiple Views sharing the same instance of a store
If you want to create different views on the exactly same set of data, i would go for
1 Model, 1 controller, 1 store, n views
In my fieldmanager app, i have a calendar like daily view and a court view, both showing the events of the same selected day. so it is important that both views do not only have the same store class, but the same instance of that store as well.
So i would go for an event controller handling both view.
I hope the ideas point in the direction the team wants to go with ext js 4, otherwise please let me know. discussions on other more advanced usecases are welcome! At the moment i am fighting a lot with the implementation
thanks and best regards
tobiu
-
28 Apr 2011 2:28 AM #2
still thinking about this. if you do not use strings to fast address the stores, it might work to use just 1 controller. i will try it out this evening.
Code:Ext.define('AM.controller.Users', { extend: 'Ext.app.Controller', stores: [ this.storeIntance1 = Ext.create('AM.store.Users'), this.storeIntance2 = Ext.create('AM.store.Users') ], ... });
-
28 Apr 2011 5:00 AM #3Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- Frederick MD, NYC, DC
- Posts
- 16,170
- Vote Rating
- 33

Jay Garcia @ModusJesus || Modus Create co-founder
Ext JS in Action author
Sencha Touch in Action author
Get in touch for Ext JS & Sencha Touch Touch Training
We are also working on Video-based Sencha Touch training: Check it out here.
-
28 Apr 2011 5:10 AM #4
i would use the app references to store to create instances at any time. The nice thing in MVC is that you always have a reference to all controllers, models, stores and views, doesn't matter from which place.
Anyway as there are many ways to do this, we still need a "good practise" for complex things. The samples are too easy to create complex applications out of them.vg Steffen
--------------------------------------
Release Manager of TYPO3 4.5
energlobe.de - german online magazine
-
28 Apr 2011 5:13 AM #5Sencha - Community Support Team
- Join Date
- Nov 2008
- Location
- San Diego, Peoples' Republic of California
- Posts
- 2,050
- Vote Rating
- 11
-
28 Apr 2011 5:28 AM #6
that's always the case with pseudocode

Code:Ext.create('World.Peace', { extend: 'Universe.Order', uses: 'World.Sunshine, World.Goodness', requires: 'A.lot.of.Money' }).show(true);vg Steffen
--------------------------------------
Release Manager of TYPO3 4.5
energlobe.de - german online magazine
-
28 Apr 2011 5:30 AM #7
fine now?Code:Ext.define('AM.controller.Users', { extend: 'Ext.app.Controller', stores: [ Ext.create('AM.store.Users', {storeId: 'storeIntance1'}), Ext.create('AM.store.Users', {storeId: 'storeIntance2'}) ], ... });
come on, this topic is not about the syntax but about the general best practices and possibilities of the currently impemented mvc.
the interesting part is, if you need one controller or multiple instances for multiple views.
best regards
tobiu
-
3 May 2011 3:15 PM #8
Tobias,
I don't think that is going to work. In the MVC examples, each view is tied to a specific store, each controller is tied to specific stores, views, and models, and each store is tied to a specific proxy (I need distinct proxies with the same MVC structure). I think that, to make this work, each one will have to have config values defined at all levels, starting like you did above, but with every reference into the MVC tree.
If we don't here back from anyone on this, I think that we may be forced to building out own MVC 'factory'. Not impossible, just a pain in the neck.
Honestly, I don't think the good folks at Sencha have gotten that far yet, but I could be wrong.
Randy
-
4 May 2011 1:57 AM #9
hi randy,
i spent quite some time on this. i think going for classes a bit like in ext 3 style is probably a good idea. you can specify multiple instances of a view sharing one controller, but it does not feel like a clean solution.
this way the first store gets the auto-generated store instance of the controller and the second view its own store. the controller can handle it (tested some events).Code:items : [{ xtype : 'messageslist', title : 'forum 1' }, { xtype : 'messageslist', title : 'forum 2', store : Ext.create('App.store.MessagesStore', {...}) }
if you leave out the red line, both instances share one store. if you give it to both, you get 3 stores.
the cleaner way would be to create new child classes of the view each time, extending the original one almost without changing something and save it into a new file. quite a lot of boiler code though.
best regards
tobiu
-
4 May 2011 1:06 PM #10
I have been wondering how you might accomplish having two or more of the same controller each managing a complex custom component.
Say I have two complex window extensions (same xtype) open that are each managed by their own (but same) controller. I don't want the controller events to collide across windows. I think this is an extremely common use case and is not address by the MVC examples.
Similar Threads
-
Best Practices
By Rohall in forum Sencha Touch 1.x: DiscussionReplies: 2Last Post: 14 Jul 2010, 1:14 PM -
best practices
By YankeeImperialistDog in forum Ext 3.x: Help & DiscussionReplies: 2Last Post: 18 Dec 2009, 5:42 AM -
Best Practices
By eknock in forum Community DiscussionReplies: 4Last Post: 29 Jul 2009, 7:58 AM -
Ext Best Practices
By justCharlie in forum Ext 2.x: Help & DiscussionReplies: 2Last Post: 14 Mar 2008, 9:59 AM


Reply With Quote