-
26 Mar 2012 7:46 PM #1
Where is best place to implement listeners
Where is best place to implement listeners
I don't directly instantiate my panels. Right now I use 'xtype' in the items config and this automatically instantiates the right classes. Since it is not recommended to implement the listeners in the 'Ext.define' where is a good place to put the listeners when using xtype in items config?
TIA,
FR
-
27 Mar 2012 5:30 AM #2
It really depends on what the listener needs to do. If you click a button and need to submit a form then use control {} in the controller. If you click a checkbox and need to disable some fields then your view can handle the listener internally. Sometimes custom events make more sense - like have your view listen for a button click and fire a custom event like fireEvent('unregisterUser').
I think what the framework wants you to avoid is doing something like this in your controller.
The above is for view events. The other type of events we use a lot are application events (controller to controller for example). We put these in init() in the controller.Code:Ext.create('App.view.MyView', { ... listeners: {} });
Code:init: function() { var me = this; me.getApplication().on({ showPayment: me.show, scope: me }); },
-
27 Mar 2012 6:00 AM #3
Thanks for your reply. Since I am not directly instantiating the class I'm still not sure where to put the listeners. For instance I'd like to do something in the painted event or a tap event.
-
27 Mar 2012 6:04 AM #4
Doesn't matter if you use Ext.create or xtype. Add your listener to control {} and it will pick it up.
-
27 Mar 2012 6:13 AM #5


Reply With Quote