Results 1 to 3 of 3

Thread: Ext.AbstractManager.onAvailable listener isn't removed properly

    Success! Looks like we've fixed this one. According to our records the fix was applied for EXTJS-6484 in a recent build.
  1. #1
    Sencha Premium Member
    Join Date
    Apr 2011
    Location
    Doylestown, PA
    Posts
    15
    Vote Rating
    1
      0  

    Default Ext.AbstractManager.onAvailable listener isn't removed properly

    REQUIRED INFORMATION

    Ext version tested:

    • Ext 4.1

    Browser versions tested against:

    • Google Chrome 19

    DOCTYPE tested against:

    • <!DOCTYPE html>

    Description:

    • onAvailable function in class Ext.AbstractManager fails, because not the proper function will be removed after component being available.

    Steps to reproduce the problem:

    • Create onAvailable listener on component with id 'test'.
    • Create the component with id 'test'.
    • Function registered will fire once.
    • Destroy the component.
    • Add onAvailable listener on component with id 'test' again.
    • Create the component again with id 'test'.
    • Function will be fired twice...

    The result that was expected:

    • Callback should fire only one, once the component is available with the specified id.

    The result that occurs instead:

    • Function called as many times as onAvailable listener applied, even if the component was destroyed, then created again between each listener apply.

    Test Case:
    Code:
    Ext.ComponentManager.onAvailable('test', function() {
    alert('I am available, first!');
    });
    
    var component = Ext.create('Ext.Component', {
    id: 'test'
    });
    
    component.destroy();
    
    Ext.ComponentManager.onAvailable('test', function() {
    alert('I am available, second!');
    });
    
    Ext.create('Ext.Component', {
    id: 'test'
    });?
    

    HELPFUL INFORMATION

    Screenshot or Video:

    • none

    See this URL for live test case: http://jsfiddle.net/fNnzF/3/


    Debugging already done:

    • yes

    Possible fix:
    Code:
    onAvailable : function (id, callback, scope) {
        var all = this.all,
        item,
        fn;
        if (all.containsKey(id)) {
            item = all.get(id);
            callback.call(scope || item, item);
        } else {
            fn = function (map, key, item) {
                if (key == id) {
                    callback.call(scope || item, item);
                    all.un('add', fn);
                }
            };
            all.on('add', fn);
        }
    }
    Additional CSS used:

    • only default ext-all.css

    Operating System:

    • Windows 7

  2. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,389
    Vote Rating
    497
      0  

    Default

    Thank you for the report!

    Regards,
    Scott.

  3. #3
    Sencha User
    Join Date
    Apr 2007
    Posts
    164
    Vote Rating
    0
      0  

    Default

    This fix introduced new bug
    Try to add two 'onAvailable' listeners
    Code:
    Ext.ComponentManager.onAvailable('test1', function() {
         alert('I am available, first!');
    });
    
    Ext.ComponentManager.onAvailable('test2', function() {
         alert('I am available, second!');
    });
    
    var component = Ext.create('Ext.Component', {
    id: 'test1'
    });
    In this case, we will get an exception because event is removed during event firing

Tags for this Thread

Posting Permissions

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