-
30 Mar 2012 6:14 AM #1
[4.1 RC1] addListener before constructor broken
[4.1 RC1] addListener before constructor broken
Ext version tested:
- Ext 4.1 RC1
- Chrome 17
- Firefox 11
- XHTML 1.0 Transitional
- 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.
- 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
- A listener is added to the object
- Crash with "Cannot read property" on line "me.hasListeners[ename] = (me.hasListeners[ename]||0) + 1;" in addListener function of Ext.util.Observable
- init hasListeners in Observable's prototype or check for init in addListener function
- Ubuntu
-
31 Mar 2012 9:05 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,714
- Vote Rating
- 438
Can I get a test case. This in 4.0.7 didn't work for me:
I get an error that the event is undefined.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'); } });Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
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 almost in print!
When posting code, please use BBCode's CODE tags.
-
3 Apr 2012 5:42 AM #3
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>
Wait! Looks like we don't have enough information to add this to bug database. Please follow this template bug format.


Reply With Quote