PDA

View Full Version : [4.1.x] Ext.util.Observable.addListener: hasListeners is undefined



Ex_Soft
10 Jul 2012, 1:05 AM
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title>Test class with events</title>
<!-- <script charset="utf-8" src="http://dev.sencha.com/deploy/ext-4.0.7-gpl/ext-all-debug.js"></script> -->
<script charset="utf-8" src="http://dev.sencha.com/deploy/ext-4.1.0-gpl/ext-all-debug.js"></script>
<!-- <script charset="utf-8" src="../../../../../ExtJS/ExtJS4/ExtJS4.1.1/ext-all-debug.js"></script> -->
<script>
Ext.Loader.setConfig({
enabled: true,
disableCaching: false
});

Ext.define("TestClass", {
singleton: true,

mixins: {
observable: "Ext.util.Observable"
},

constructor: function(config) {
this.addEvents("testevent");
this.addListener("testevent", this.onTestEvent, this); // hasListeners is undefined if (hasListeners.hasOwnProperty(ename)) { ext-all-debug.js 24671
},

onTestEvent: function() {
if(window.console && console.log)
console.log("TestClass.onTestEvent(%o)", arguments);
}
});

Ext.onReady(function() {
if(window.console && console.clear)
console.clear();

if(window.console && console.log)
console.log("core: %s, extjs: %s", Ext.versions.core.version, Ext.versions.extjs.version);

TestClass.fireEvent("testevent", { eventName: "TestEvent" });
});
</script>
</head>
<body>
</body>
</html>

4.0.7 works fine. What should I change?

P.S.

<script charset="utf-8" src="http://dev.sencha.com/deploy/ext-4.1.1-gpl/ext-all-debug.js"></script>

"NetworkError: 404 Not Found - http://dev.sencha.com/deploy/ext-4.1.1-gpl/ext-all-debug.js" Where is 4.1.1 on sencha.com?

Ex_Soft
10 Jul 2012, 1:41 AM
// we need this before we call initComponent
if (!me.hasListeners) {
me.hasListeners = new me.HasListeners();
}




<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title>Test class with events</title>
<script charset="utf-8" src="http://dev.sencha.com/deploy/ext-4.1.0-gpl/ext-all-debug.js"></script>
<!-- <script charset="utf-8" src="../../../../../ExtJS/ExtJS4/ExtJS4.1.1/ext-all-debug.js"></script> -->
<script>
Ext.Loader.setConfig({
enabled: true,
disableCaching: false
});

Ext.define("TestClass", {
singleton: true,

mixins: {
observable: "Ext.util.Observable"
},

constructor: function(config) {
if(!this.hasListeners)
this.hasListeners = new this.HasListeners();

this.addEvents("testevent");
this.addListener("testevent", this.onTestEvent, this);
},

onTestEvent: function() {
if(window.console && console.log)
console.log("TestClass.onTestEvent(%o)", arguments);
}
});

Ext.onReady(function() {
if(window.console && console.clear)
console.clear();

if(window.console && console.log)
console.log("core: %s, extjs: %s", Ext.versions.core.version, Ext.versions.extjs.version);

TestClass.fireEvent("testevent", { eventName: "TestEvent" });
});
</script>
</head>
<body>
</body>
</html>

works. But I'm not sure what this is really necessary.

Ex_Soft
10 Jul 2012, 11:08 PM
Is this a bug (http://www.sencha.com/forum/showthread.php?208714-Ext.util.Observable-broken-in-4.1.1.RC&highlight=hasListeners+undefined)?

burnnat
11 Jul 2012, 6:31 AM
It's not a bug - you need to call the constructor for the Observable mixin. In the past, things would still work without calling the constructor, but that was by coincidence, not by design.

In your class constructor, add:

this.mixins.observable.constructor.call(this);

Ex_Soft
11 Jul 2012, 6:54 AM
you need to call the constructor for the Observable mixin
Ok

Possibly would be wise to mention it in the documentation, and in examples, where Observable is mixed in to classes, otherwise it's a bit misleading. (http://www.sencha.com/forum/showthread.php?208714-Ext.util.Observable-broken-in-4.1.1.RC&p=812030&viewfull=1#post812030)