Hi all,
I'm still fairly new to Sencha Touch, so please bear with me if this is a stupid question. 
It seems you can add behaviors to view components by either implementing a controller, or by adding an event listener right in the view component. The documentation explains how to do each, but doesn't really explain when you should use one over the other.
Here's my concrete example: I am creating a subclass of Ext.tab.Panel that allows swiping between tabs. On the initialize event, I go through and add the swipe event listener to each item's element. There are two ways to do this (I've implemented both as a learning exercise):
Approach 1: Event listener in the tabpanel subclass:
Code:
Ext.define("MyApp.view.SwipeTabPanel", {
extend: 'Ext.tab.Panel',
xtype: 'swipeTabPanel',
config: {
listeners: {
initialize: function() {
// do the work here
}
}
});
Approach 2: Use a controller
View component:
Code:
Ext.define("MyApp.view.SwipeTabPanel", {
extend: 'Ext.tab.Panel',
xtype: 'swipeTabPanel'
});
Controller:
Code:
Ext.define('MyApp.controller.TabSwipe', {
extend: 'Ext.app.Controller',
config: {
control: {
'swipeTabPanel': {
initialize: 'addSwipeListener'
}
}
},
addSwipeListener: function(comp, opts) {
// do the work here
}
});
Both of these work, but I'm not sure which is the "right way" to do it in Sencha Touch 2.
Thanks in advance.