PDA

View Full Version : Extending Ext.util.Observable



jbraband
23 Feb 2007, 12:31 PM
I extend Ext.util.Observable as I've done in .40, I get the following error:

l.fireFn has no properties
at line 1716 of ext-all-debug.js (i think its rev 9)

it is the fire method

1713 fire : function(){
1712 var args = Array.prototype.slice.call(arguments, 0);
1713 var ls = this.listeners, scope;
1714 for(var i = 0, len = ls.length; i < len; i++){
1715 var l = ls[i];
1716 if(l.fireFn.apply(l.scope, arguments) === false){
1717 return false;
1718 }
1719 }
1720 }

here is my simplified code




MainInterface = function(){
};


Ext.extend(MainInterface, Ext.util.Observable, {
init: function() {

}
});

Ext.EventManager.onDocumentReady(MainInterface.init, MainInterface, true);



any ideas off the top of your head?

Belgabor
23 Feb 2007, 2:16 PM
I don't know how it worked in 0.4, but here is a object I wrote inheriting from Observable that works in 1.0a:


CountUpDown = function(config) {
config = config || {};
Ext.apply(this, config);
if (!this.counter_init)
this.counter_init = 0;
if (!this.stop_at)
this.stop_at = 0;
if (!this.counter_step)
this.counter_step = 1;
this.events = {
up: true,
down: true,
ready: true
};
};

Ext.extend(CountUpDown, Ext.util.Observable, {
up : function (step) {
if (!step)
step = this.counter_step;
this.counter_init += step;
this.fireEvent("up", step, this.counter_init);
if (this.counter_init == this.stop_at)
this.fireEvent("ready");
},
down : function (step) {
if (!step)
step = this.counter_step;
this.counter_init -= step;
this.fireEvent("down", step, this.counter_init);
if (this.counter_init == this.stop_at)
this.fireEvent("ready");
}
});

jack.slocum
23 Feb 2007, 2:21 PM
fireFn has no properties means that the function you passed in when you add your listner is invalid (undefined).

I also notice your code is combining two concepts. You have a class defined (MainInterface), and your are trying to call the init method without an instance of the class.

MainInterface = function(){
};

Ext.extend(MainInterface, Ext.util.Observable, {
init: function() {

}
});
// here's the problem, MainInterface is a class and init() can't be
// called without an instance
Ext.EventManager.onDocumentReady(MainInterface.init, MainInterface, true);

I am guessing you want to create a globally available singleton, that is also Observable? If I am right, let me know. I would be glad to provide a sample.

jbraband
23 Feb 2007, 2:36 PM
wow...wow...wow...

wow.

:oops:

thanks jack.

this is like whiffing on an open net goal with Wayne Gretsky watching :lol:

jack.slocum
23 Feb 2007, 2:40 PM
Noooo. It's like whiffing on the first pitch of the world series, but hopefully hitting a homerun on the second. :)

jbraband
23 Feb 2007, 2:45 PM
i cranked it of the park with this (for those reading this thread with a similar problem)



var mi = new MainInterface();
Ext.onReady(mi.init, MainInterface, true);

jack.slocum
23 Feb 2007, 2:53 PM
Good thing you get 3 pitches! ;)

var mi = new MainInterface();
Ext.onReady(mi.init, mi);

jbraband
23 Feb 2007, 2:57 PM
yeah, so uh.... :roll:

sacrifice bunt?

i was just having issues with scoping :roll: and uh...you da man :wink:

NoDice
4 Apr 2007, 6:38 AM
I am guessing you want to create a globally available singleton, that is also Observable? If I am right, let me know. I would be glad to provide a sample.

This is exactly what I am trying to do but have been unsuccessful thus far. Would you please provide an example?

Thanks

jack.slocum
4 Apr 2007, 4:48 PM
If you wanted the actual Impl class to be private:



MyObservableSingleton = function(){
var Impl = function(){ // this is your class
// your constructor
};
Ext.extend(Impl, Ext.util.Observable, {
// your functions
});

return new Impl();
}();


If you want the actual class to be public, take a look at TaskMgr and TaskRunner in the util directory of the Ext beta1. It doesn't use Observable, but Ext.TaskMgr is a singleton Ext.util.TaskRunner.

NoDice
5 Apr 2007, 3:05 PM
Thanks Jack,
This is the pattern I was looking for... I will study the TaskMgr/TaskRunner in more depth @ a later time.

Animal
5 Apr 2007, 10:41 PM
I have a singleton which extends Observable. I used:



MyObservableSingleton = function(){
return Ext.apply(new Ext.util.Observable (), {
init: function() {
},

doStuff: function() {
}
});
}();