1. #1
    Sencha User
    Join Date
    Jul 2010
    Posts
    43
    Vote Rating
    1
    farbodr is on a distinguished road

      0  

    Default 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

  2. #2
    Ext JS Premium Member
    Join Date
    Apr 2010
    Location
    Omaha, NE
    Posts
    556
    Vote Rating
    25
    estesbubba will become famous soon enough estesbubba will become famous soon enough

      0  

    Default


    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.

    Code:
    Ext.create('App.view.MyView', {
        ...
        listeners: {}
    });
    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:
        init: function() {
            var me = this;
    
    
            me.getApplication().on({
                showPayment: me.show,
                scope: me
            });
        },

  3. #3
    Sencha User
    Join Date
    Jul 2010
    Posts
    43
    Vote Rating
    1
    farbodr is on a distinguished road

      0  

    Default


    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.

  4. #4
    Ext JS Premium Member
    Join Date
    Apr 2010
    Location
    Omaha, NE
    Posts
    556
    Vote Rating
    25
    estesbubba will become famous soon enough estesbubba will become famous soon enough

      0  

    Default


    Doesn't matter if you use Ext.create or xtype. Add your listener to control {} and it will pick it up.

  5. #5
    Sencha User
    Join Date
    Jul 2010
    Posts
    43
    Vote Rating
    1
    farbodr is on a distinguished road

      0  

    Default


    ok. thanks.

Thread Participants: 1