Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Extending Ext.util.Observable

  1. #1
    Sencha User
    Join Date
    Mar 2007
    Location
    Minneapolis, MN, USA
    Posts
    72

    Default Extending Ext.util.Observable

    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

    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?

  2. #2

    Default

    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:

    Code:
    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");
    	}
    });

  3. #3
    Sencha User jack.slocum's Avatar
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    6,956

    Default

    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.

  4. #4
    Sencha User
    Join Date
    Mar 2007
    Location
    Minneapolis, MN, USA
    Posts
    72

    Default

    wow...wow...wow...

    wow.

    :oops:

    thanks jack.

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

  5. #5
    Sencha User jack.slocum's Avatar
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    6,956

    Default

    Noooo. It's like whiffing on the first pitch of the world series, but hopefully hitting a homerun on the second.

  6. #6
    Sencha User
    Join Date
    Mar 2007
    Location
    Minneapolis, MN, USA
    Posts
    72

    Default

    i cranked it of the park with this (for those reading this thread with a similar problem)

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

  7. #7
    Sencha User jack.slocum's Avatar
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    6,956

    Default

    Good thing you get 3 pitches!

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

  8. #8
    Sencha User
    Join Date
    Mar 2007
    Location
    Minneapolis, MN, USA
    Posts
    72

    Default

    yeah, so uh.... :roll:

    sacrifice bunt?

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

  9. #9

    Default

    Quote Originally Posted by jack.slocum View Post
    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

  10. #10
    Sencha User jack.slocum's Avatar
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    6,956

    Default

    If you wanted the actual Impl class to be private:

    Code:
    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.
    Jack Slocum
    Sencha Co-Founder, Ext JS Founder
    Original author of Ext JS 1, 2 & 3.
    Twitter: @jackslocum

Page 1 of 2 12 LastLast

Similar Threads

  1. Observable not getting custom args
    By CableDawg in forum Ext 1.x: Help & Discussion
    Replies: 6
    Last Post: 10 Apr 2007, 12:17 PM
  2. Observable.fire - behaviour changed.
    By Animal in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 23 Feb 2007, 7:19 AM
  3. EventProvider vs. Observable (choose one?)
    By kalebwalton in forum Community Discussion
    Replies: 5
    Last Post: 9 Dec 2006, 1:48 PM
  4. Little bug in docs of Observable.fireEvent
    By Animal in forum Ext 1.x: Bugs
    Replies: 0
    Last Post: 22 Nov 2006, 3:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •