-
21 Feb 2012 5:09 AM #1
Unanswered: Listener best practice
Unanswered: Listener best practice
Is it generally considered best practice to add listeners for UI interaction (button presses/list item taps/etc) within a controller or within the views themselves?
-
21 Feb 2012 9:22 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,714
- Vote Rating
- 438
- Answers
- 3113
Kind of depends. The logic needs to be in the controller so you can put the listeners and logic in the controller. The only reason why I would say you can listen for it in a view (minus not using MVC) is to fire a custom event. I have created a container which has many children but I don't want the controller to have too intiment knowledge of how a view is structured so I have the container listen for events on it's children and then fire a custom event on itself. Then if I ever have to change the layout on that container, I only have to change the view not find where that logic is implemented in any controller.
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
21 Feb 2012 9:24 AM #3
That makes sense. So your controller would still listen for your custom event, but the view would handle capturing the component event and translating it to your custom event, correct?
-
21 Feb 2012 9:27 AM #4Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,714
- Vote Rating
- 438
- Answers
- 3113
Yes, correct. Basically turning that container into a fully fledged widget that can handle itself apart from an application.
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.


Reply With Quote