1. #1
    Sencha User
    Join Date
    Jan 2012
    Posts
    116
    Vote Rating
    16
    Notepad123 will become famous soon enough

      0  

    Default Object listeners NOT overriding class listeners

    Object listeners NOT overriding class listeners


    Ok, so as proposed in following links
    http://www.sencha.com/forum/showthre...06#post1069806
    https://web.archive.org/web/20120517...-property-bad/
    http://stackoverflow.com/questions/1...-in-ext-define

    the proper way to add listeners to a class is to use on() in some class method that executes during object creaton.

    On other hand this seems more like a workaround to a much simpler solution of simply adding listeners property to config property the same you would do when creating listeners during object creation. This way is great since it allows you to create class listeners in a simpler way and this way is consistent with the way listeners are created during object creation. The problem is that these class listeners get overwritten if you use listeners property during object creation.

    So my question is if something could be changed so that object's listeners property doesn't override classes listeners property but only overrides listeners that are redefined in objects listener property. Is this possible? If not why not?

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,650
    Vote Rating
    899
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    The issue here is conflicts when create the class and pass listeners. So imagine you had this:

    Code:
    Ext.define('Ux.Button', {
        extend : 'Ext.Button',
        xtype  : 'ux-button',
    
        config : {
            listeners : {
                tap : 'handleTapEvent'
            }
        },
    
        handleTapEvent : function() {}
    });
    And you create an istance:

    Code:
    Ext.create('Ux.Button', {
        text : 'Foo'
    });
    Ok, so the tap event will then fire the handleTapEvent method. Great! Now, I can easily break it by creating an instance with a tap listener:

    Code:
    Ext.create('Ux.Button', {
        text : 'Foo',
        listeners : {
            tap : function() {}
        }
    });
    Now the handleTapEvent method will not execute because of the listeners on the instance creation is overriding it.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Jan 2012
    Posts
    116
    Vote Rating
    16
    Notepad123 will become famous soon enough

      0  

    Default


    So now that I understand how this currently works my question would be is there anything that can be done do change it how it works. Both Ext.define and Ext,create are Sencha Touch functions and they can do whatever they want with it.

    So it seems to me that it should be possible that they
    - take listeners property from Ext.create parameter
    - go through the listeners defined in it
    - and then maybe use on() method to add to class new listeners defined in the object , rather then simple taking listener property defined in Object and use it to override the listener property defined in class.

    I presume this is how we programmers would like this to work rather then having to resort to workarounds using on() ourself forcing us to use Procedural instead of declerative sytax.

Thread Participants: 1