Thank you for reporting this bug. We will make it our priority to review this report.
  1. #1
    Ext JS Premium Member gevik's Avatar
    Join Date
    May 2009
    Location
    The Netharlands
    Posts
    272
    Vote Rating
    24
    gevik will become famous soon enough gevik will become famous soon enough

      0  

    Exclamation [FIXED-EXTJSIV-272] Ext.util.Observable as mixin serious limitation

    [FIXED-EXTJSIV-272] Ext.util.Observable as mixin serious limitation


    I have been trying to override Ext.util.Observable's functions (fireEvent and ctor) to add some custom stuff to be used globally. I followed the callOverridden example which at first looks just wonderful.

    However after creating a very simple implementation I get the following error:

    [Ext.button.Button#callOverridden] Calling a protected method from the public scope
    ext-core-debug.js Line 2383


    Here is the code:
    Code:
        Ext.override(Ext.util.Observable,{
    
            constructor:function()
            {
                console.log('custom ctor');
                this.callOverridden(arguments);
            },
    
            fireEvent:function()
            {
                console.log('customer fireEvent');
                this.callOverridden(arguments);
            }
        });
    
        Ext.onReady(function(){
            Ext.create('Ext.button.Button',{
                text:'Click Me',
                scale:'large',
                renderTo:Ext.getBody()}
        );
        })
    Am I doing something wrong here?

    After digging in the stack-trace I found the problem at Ext.AbstractComponent's constructor:

    Code:
    me.mixins.observable.constructor.call(me);
    The way mixins are utilized in the framework, like the code fragment above, also prevents interceptors and sequences to function correctly on classes which are used as mixins. After testing I found that only the original function is called. The interceptor is not called.

    Now, I asked this question before, but did not get a founded answer. So here it goes again:
    Since 98% of all the functionality in the framework has something to do with events and event handlers why on earth is the Ext.util.Observable not used as a base class for classes which need to have observability? Like the Ext.AbstractComponent!

    Second, Why is the usage of Ext.util.Observable not consistent. Like in the Ext.Application which extends from Ext.util.Observable and not uses it as mixin.

    Please clarify

  2. #2
    Sencha User Jacky Nguyen's Avatar
    Join Date
    Jul 2009
    Location
    Palo Alto, California
    Posts
    469
    Vote Rating
    14
    Jacky Nguyen has a spectacular aura about Jacky Nguyen has a spectacular aura about

      0  

    Default


    Please use the override static class method instead. This should work:

    Code:
    Ext.util.Observable.override({
        constructor:function() {
            console.log('custom ctor');
            this.callOverridden(arguments);
        },
    
        fireEvent:function() {
            console.log('customer fireEvent');
            this.callOverridden(arguments);
        }
    });
    Sencha Touch Lead Architect

  3. #3
    Sencha User Jacky Nguyen's Avatar
    Join Date
    Jul 2009
    Location
    Palo Alto, California
    Posts
    469
    Vote Rating
    14
    Jacky Nguyen has a spectacular aura about Jacky Nguyen has a spectacular aura about

      0  

    Default


    Ext.override has been made an alias to Ext.Base.override. Both ways will work from the next release onwards.
    Sencha Touch Lead Architect

  4. #4
    Ext JS Premium Member gevik's Avatar
    Join Date
    May 2009
    Location
    The Netharlands
    Posts
    272
    Vote Rating
    24
    gevik will become famous soon enough gevik will become famous soon enough

      0  

    Exclamation Ext.util.Observable as mixin serious limitation (2)

    Ext.util.Observable as mixin serious limitation (2)


    The static override method only worked for the ctor but not for the fireEvent override!
    Is this also in the fix for the next release?
    Code:
        Ext.util.Observable.override({
            constructor:function() {
                console.log('custom ctor');
                this.callOverridden(arguments);
            }
        });
    
        Ext.util.Observable.override({
            fireEvent:function() {
                console.log('customer fireEvent');
                return this.callOverridden(arguments);
            }
        });
    
        Ext.onReady(function(){
            Ext.create('Ext.button.Button',{
                text:'Click Me',
                scale:'large',
                listeners:{
                    click:function()
                    {
                        console.log('from button');
                    }
                },
                renderTo:Ext.getBody()}
            );
        })

  5. #5
    Sencha User Jacky Nguyen's Avatar
    Join Date
    Jul 2009
    Location
    Palo Alto, California
    Posts
    469
    Vote Rating
    14
    Jacky Nguyen has a spectacular aura about Jacky Nguyen has a spectacular aura about

      0  

    Default


    DOM events are not fired via Ext.util.Observable#fireEvent at the moment, but rather via Ext.util.Event#fire. Hence if you want to intercept DOM events, this should work:

    Code:
    Ext.util.Event.override({
        fire: function() {
            console.log('before fire...');
            this.callOverridden(arguments);
            console.log('after fire...');
        }
    });
    Sencha Touch Lead Architect

  6. #6
    Ext JS Premium Member gevik's Avatar
    Join Date
    May 2009
    Location
    The Netharlands
    Posts
    272
    Vote Rating
    24
    gevik will become famous soon enough gevik will become famous soon enough

      0  

    Default


    Quote Originally Posted by Jacky Nguyen View Post
    DOM events are not fired via Ext.util.Observable#fireEvent at the moment, but rather via Ext.util.Event#fire. Hence if you want to intercept DOM events, this should work:
    It works as you provided in the code. Thank you.
    But don't you think this behavior is kind of confusing? This means that one has to override within different levels of the framework to get something this simple accomplished!

    Is this behavior going to stay or can we expect DOM events being fired via Ext.util.Observable#fireEvent ?

  7. #7
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    17,164
    Vote Rating
    674
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    It has always been this way. They are 2 separate event structures, I don't think it's a good idea to mix the management of synthetic events with real DOM events.

    DOM events also have several options (delegate, target) that aren't available to synthetic events.
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  8. #8
    Ext JS Premium Member gevik's Avatar
    Join Date
    May 2009
    Location
    The Netharlands
    Posts
    272
    Vote Rating
    24
    gevik will become famous soon enough gevik will become famous soon enough

      0  

    Default


    Makes perfectly sense, thank you both.

Similar Threads

  1. Extending Ext.Util.Observable
    By ajay.kumar2 in forum Ext 3.x: Help & Discussion
    Replies: 4
    Last Post: 13 Nov 2010, 7:39 AM
  2. Replies: 3
    Last Post: 19 Mar 2010, 8:21 AM
  3. Ext.util.Observable();
    By kamakrane in forum Ext 3.x: Help & Discussion
    Replies: 2
    Last Post: 6 Nov 2009, 11:43 AM
  4. Ext.util.Observable.addEvents ???
    By chalu in forum Ext 2.x: Help & Discussion
    Replies: 4
    Last Post: 2 Jun 2008, 5:54 AM

Thread Participants: 2