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

Thread: Ext.util.Observable -> hasListener method is always returning true

    Success! Looks like we've fixed this one. According to our records the fix was applied for EXTJS-6829 in 4.1.2.
  1. #1
    Sencha Premium User wemerson.januario's Avatar
    Join Date
    Nov 2008
    Location
    Goiânia - GO, Brazil
    Posts
    903

    Default Ext.util.Observable -> hasListener method is always returning true

    Ext.util.Observable hasListener is diferent when comparing to ExtJS 4.1.0 beta 2
    Beta 2 Works
    Code:
      hasListener: function(ename) {        var event = this.events[ename.toLowerCase()];
            return event && event.isEvent === true && event.listeners.length > 0;
    
        },

    Beta 3 does not work
    Code:
    hasListener: function(ename) {        return !!this.hasListeners[ename.toLowerCase()];
    
        },

    Ext version tested:
    • Ext 4.1.0 Beta 3
    Browser versions tested against:
    • Any browser
    Description:
    • Ext.util.Observable -> hasListener method is always return true
    The result that was expected:
    • Checks to see if this object has any listeners for a specified event and return true ou false
    The result that occurs instead:
    • always returning true
    Test case:
    Code:
    Ext.onReady(function() {    
        var p = Ext.create('Ext.panel.Panel');
    
    
        console.log(p.hasListener('anything_you_put_here_always_return_true'));
        
    
    });

    Wemerson Januario @JanuarioCoder
    Novanti Tecnologia, Sencha MVP/ Ext JS Consultant
    ____________________________________________
    Hire me on UpWork:

    GitHub
    https://github.com/wemersonjanuario

    Treinamento e Consultoria Ext JS. QUALIFIQUE-SE JÁ!

  2. #2
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,258

    Default

    Please post a test case:

    Code:
    Ext.onReady(function() {
        
        var p = Ext.create('Ext.panel.Panel');
        console.log(p.hasListener('render'));
        
    });
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

  3. #3
    Sencha Premium User wemerson.januario's Avatar
    Join Date
    Nov 2008
    Location
    Goiânia - GO, Brazil
    Posts
    903

    Default

    Quote Originally Posted by evant View Post
    Please post a test case:

    Code:
    Ext.onReady(function() {
        
        var p = Ext.create('Ext.panel.Panel');
        console.log(p.hasListener('render'));
        
    });
    now is updated! is it suficient?
    thanks
    Wemerson Januario @JanuarioCoder
    Novanti Tecnologia, Sencha MVP/ Ext JS Consultant
    ____________________________________________
    Hire me on UpWork:

    GitHub
    https://github.com/wemersonjanuario

    Treinamento e Consultoria Ext JS. QUALIFIQUE-SE JÁ!

  4. #4
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,258

    Default

    No, I wasn't able to reproduce it. I ran your sample code in B3 in Chrome/FF/IE and it returned false in every case.
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

  5. #5
    Sencha Premium User wemerson.januario's Avatar
    Join Date
    Nov 2008
    Location
    Goiânia - GO, Brazil
    Posts
    903

    Default

    this was not fixed yet
    Wemerson Januario @JanuarioCoder
    Novanti Tecnologia, Sencha MVP/ Ext JS Consultant
    ____________________________________________
    Hire me on UpWork:

    GitHub
    https://github.com/wemersonjanuario

    Treinamento e Consultoria Ext JS. QUALIFIQUE-SE JÁ!

  6. #6
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,258

    Default

    As I said above I wasn't able to reproduce this, can you post a test case that demonstrates the issue?
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

  7. #7
    Sencha Premium Member
    Join Date
    Feb 2012
    Location
    Raleigh, NC
    Posts
    435

    Default

    I am also seeing this. A simple test case is below, along with the values I get. As you can see, even after clearing the listeners, hasListener() still returns true, even though the listeners array is empty.

    Code:
    var hasListenerCheck1, hasListenerCheck2, hasListenerCheck3, listenerLengthCheck1, listenerLengthCheck2, testHandler, testObservable;
    
    
    testHandler = function() {
    	return true;
    };
    
    
    testObservable = Ext.create('Ext.util.Observable');
    
    
    hasListenerCheck1 = testObservable.hasListener('myTestEventName'); //false
    
    testObservable.on('myTestEventName', testHandler(), this);
    hasListenerCheck2 = testObservable.hasListener('myTestEventName'); //true
    listenerLengthCheck1 = testObservable.events.mytesteventname.listeners.length; //1
    
    
    testObservable.clearListeners();
    hasListenerCheck3 = testObservable.hasListener('myTestEventName'); //true?!
    listenerLengthCheck2 = testObservable.events.mytesteventname.listeners.length; //0

  8. #8
    Sencha Premium Member
    Join Date
    Feb 2012
    Location
    Raleigh, NC
    Posts
    435

    Default

    I'll also add that if I create my own class and mix in Observable, calling the constructor on Observable and passing in 'this' ( this.mixins.observable.constructor.call(this) ) as the docs show, I get the same result.

  9. #9
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,258

    Default

    Thanks for the test case.
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

  10. #10

    Default

    +1

    I'm also running into the same issue demonstrated by Brian's test case with Ext JS 4.1.1.

    This is breaking my unit tests, as I cannot accurately inspect an Observable to ensure the listeners have been cleaned up. Following a call to clearListeners(), hasListener() reports 'true' even though the internal listeners Array is empty.

Page 1 of 2 12 LastLast

Posting Permissions

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