29 Apr 2012 4:08 AM #1
What to do with multiple instances of the same view and the controller
If i am having many instances of the same view,
Should they use the same controller of have a controller instance for each of the views?
At the moment I am loading the views dynamicly and I am loading only a single view using the getController function Ext API is offering (But this methods0 check to see if a controller with the same name already been laoded and this causes for a single controller to exists.
The problem with that is that the controller now control each event from the view many times (for each instance) .
Do i need to change the code for the controller so he will know to whom to listen or to load a controller for each view instance as well???
30 Apr 2012 10:05 PM #2
1 May 2012 7:56 PM #3
Same question here
I have the same question. Searching around on google, I have seen a few implementations that use one controller for many views but they were mostly simplified views with maybe two events that interact with the controller.
These examples all have view identification logic implemented in each of the events the controller handles.
They are here on the sencha forum, example #1 and example #2.
The controller I have in mind for what I need will handle almost a hundred different view events, so I suppose I would create a method that identifies which view is dispatching the event and then call that view identification method as the first action in every event handler.
I haven't found any implementations that create a controller for each view instance though. I would prefer that personally because I expect only about 2-3 instance of this particular view (the one with 100 handlers) it also will need to have it's own instance of a couple different stores etc, and it would seem alot cleaner (and easier) to just create another controller that only talks to one view and one store. (Instead having one controller that has to figure out which view and which store it is communicating with at every event dispatch).
Those are my two cents. Any ideas on how to implement this second approach, would be much appreciated.
Here's an example of a scenario similar to mine which I am referring to above and which I think multiple controller instances would be justified - or correct me please if I am going about this the wrong way:
Say you're making a CRM which has a tabpanel as the first child of the viewport. Each client opens as a new tab, and each tab contains an accordion panel that has the client's profile with contact data in the top accordion panel, a gridpanel displaying all correspondence in the next accordion panel, a gridpanel displaying all financial actions in a third accordion panel, and a row-editing gridpanel to enter the clients address history or some other more sequitor row-editing type thing in the last accordion panel.
It would be nice to have one controller for this accordion panel that sits in one of these tabs. Then when the user want to open another client tab you simple create another instance of the controller which loads all of these views and stores, events dispatched from anywhere in the tab would all just go to the one controller they are connected to.
I will try this out and see if it is possible tomorrow.
1 May 2012 9:19 PM #4
take a look a this
1 May 2012 10:02 PM #5
That clarifies some things.
Specifically on how to handle the stores in an example like mine above. It makes sense logically that they would go into the views because that is the only thing that would ever use them. I was just getting a bit stuck on MVC recommendations. I am specifically referring to this part from Mitchell's reply:
For the Store instance on the view or a global one... depends on the needs. If you are going to use globally then make it global. If you only are going to need it on the view then put it on the view. MVC is not a law, you can change it to fit your needs. Technically the Controller part of MVC is suppose to be the middle man between the View and Model parts but sometimes that's just not needed. I create the Store in the view 95% of the time. I'll give you an example...
If you have a Store for products, you probably only need to reference that Store in your Grid. That usually isn't needed for other parts of the application. However, if you have a Store to load countries, I often need it globally so I only have to load it once and can then set/use that Store in several views.
1 May 2012 10:03 PM #6
Glad I could help
It took me 3 days to find out this answer.
I was hoping sencha would add search for their forum by the way