Reuse Views With Multiple Controllers

Reuse Views With Multiple Controllers

I am trying to reuse views with multiple controllers. The problem I run into is that the controllers are listening to the same view events. Instead of defining views in controller to I do Ext.create() within the controller init function?

A controller listens to any event that is fired based on the ComponentQuery selector you provided.

Say you have a form with some checkboxes and you want to do something with the checked event. Since you may have 100 checkboxes but the logic is the same you can use one selector:

Code:

this.control({
'formpanel checkboxfield' : {
checked : someFn
}
});

That will listen to any checkboxfield that is a child of a formpanel no matter when it is created. So you can remove and add checkboxfields and formpanels all day and this code should still listen to them

So if you have multiple instances of a view the controller should listen to events from all of those instances. If you setup a reference in the controller it should know which instance the event was fired from? So all that too say I could just use the one controller for each instance of those views?

Yes, anything that matches that selector will be listened to. The first argument of a listener will be the component firing the event.

I usually don't architect my controllers based on a view... I have controllers based on feature/function. Technically you can have just one controller but that isn't very good application architecture.

I am trying to reuse code. I have multiple tabs that serve up similar content ( list > detail ) so the functionality will be the same for each. Would you still create multiple views for each tab of content even though it is the same?