Wait! Looks like we don't have enough information to add this to bug database. Please follow this template bug format.
  1. #1
    Ext JS Premium Member
    Join Date
    Nov 2010
    Posts
    88
    Vote Rating
    2
    watermark is on a distinguished road

      0  

    Default [4.1 RC1] addListener before constructor broken

    [4.1 RC1] addListener before constructor broken


    Ext version tested:
    • Ext 4.1 RC1
    Browser versions tested against:
    • Chrome 17
    • Firefox 11
    DOCTYPE tested against:
    • XHTML 1.0 Transitional
    Description:
    • 4.0.7 supported calling addListener before the object's constructor was called. 4.1 RC1 doesn't support this, but it should be simple to reinstate this support.
    Steps to reproduce the problem:
    • Create a class that extends anything observable (ex. Ext.grid.Panel)
    • In the new object's constructor function, before calling the parent constructor, call addListener with any event
    The result that was expected:
    • A listener is added to the object
    The result that occurs instead:
    • Crash with "Cannot read property" on line "me.hasListeners[ename] = (me.hasListeners[ename]||0) + 1;" in addListener function of Ext.util.Observable
    Possible fix:
    • init hasListeners in Observable's prototype or check for init in addListener function
    Operating System:
    • Ubuntu

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,327
    Vote Rating
    850
    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


    Can I get a test case. This in 4.0.7 didn't work for me:

    Code:
    Ext.define('MyPanel', {
        extend : 'Ext.panel.Panel',
        alias  : 'widget.mypanel',
    
        title : 'Test',
        html  : 'test',
    
        constructor : function(config) {
            this.addListener('afterrender', this.onAfterRender, this);
            this.callParent([config]);
        },
    
        onAfterRender : function() {
            console.log('afterrender fired');
        }
    });
    I get an error that the event is undefined.
    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
    Ext JS Premium Member
    Join Date
    Nov 2010
    Posts
    88
    Vote Rating
    2
    watermark is on a distinguished road

      0  

    Default


    Had to call addEvents before adding an event. Seems that function inits that events array in 4.0.7.

    Code:
    <html>
    <head>
        <script type="text/javascript" src="http://dev.sencha.com/deploy/ext-4.0.7-gpl/bootstrap.js"></script>
        <script type="text/javascript">
            Ext.define('MyPanel', {
                extend : 'Ext.panel.Panel',
                alias  : 'widget.mypanel',
    
                title : 'Test',
                html  : 'test',
    
                constructor : function(config) {
                this.addEvents('blah');
                this.addListener('afterrender', this.onAfterRender, this);
                this.callParent([config]);
                },
    
                onAfterRender : function() {
                console.log('afterrender fired');
                }
            });
            
            Ext.application({
                name: 'derp',
                launch: function() {
                    Ext.create('MyPanel', {
                        renderTo: 'testdiv'
                    });
                }
            });
        </script>
    </head>
    <body>
    <div id='testdiv'></div>
    </body>
    </html>

Thread Participants: 1