View Full Version : Best place to put the event listeners (Controller or View)

31 Mar 2014, 9:47 AM

I am new to EXTjs and I have a doubt regarding the placing of the event listener

So, If I have two different panels in my application and each have two buttons.

Should I define my my event listeners for the two buttons and their subsequent actions in the controller
Should I be placing the listeners in the individual view itself?

31 Mar 2014, 12:08 PM
It is hard to say where is the best place because it depends on your application. Both places are good enough unless we are consistency with one way.

For the old application that already put Event Listener on View, I see you have no other option.

For fresh new application: I voted for put it in "Controller". The UI design guys will really appreciated this.

- View is quite complicated with rendering data and tons of configuration codes. Add more responsible to the view is not welcome.
- More easy in reuse view because it does not specific which controller can be hooked up with.
- Event, in other view, is a request to application that need to be process by Controller, right?
- If implement Event Listener on View, then when View delegate to Controller, VIew have to pass all the necessary arguments for Controller to process. This way break MVC model that View should not concern about who standing behind.

That is my thoughts. Hope this help.

31 Mar 2014, 12:14 PM
Put it in the controller :)

In Ext JS 5 we will be able to use ViewControllers (http://www.sencha.com/forum/showthread.php?283012-Ext-5-View-Controller-Event-Listening), so there will be even less incentive to put event handling code in the view.

31 Mar 2014, 6:48 PM
Thank you for the answers.
Out of curiosity, is there any other approaches being used in the industry?