[2.1] A bug in Ext.applyIf?

  • Hi,

    I'm a newbie in component authoring and I was playing around with it. So I created a simple TabTest component that encapsulates a configuration:


    Ext.TabTest = Ext.extend(Ext.TabPanel,
    {
    initComponent: function()
    {
    Ext.applyIf(this, {
    width:450,
    activeTab: 0,
    frame:true,
    defaults:{autoHeight: true},
    items:[
    {contentEl:'script', title: 'Short Text'},
    {contentEl:'markup', title: 'Long Text'}
    ]
    });

    Ext.TabTest.superclass.initComponent.call(this, arguments);
    }
    });

    var tabs = new Ext.TabTest({renderTo: "tabs1", width: 800});


    The problem here is that "activeTab" is not being applied, I suppose it's because it's value is zero and is probably failing an "if" test that checks if the value is really there.

    Regards,
    Thiago Souza


  • Ext.applyIf works fine:

    http://tdg-i.com/img/screencasts/2008-04-26_2238.swf


  • That being said, it would probably make sense to have applyIf also write to the object if it has that property, but the value is null. I don't know if it will cause any side effects elsewhere, if one of the devs could weigh in.


    applyIf: function(o, c)
    {
    if(o && c)
    {
    for(var p in c)
    {
    if(typeof o[p] == "undefined" o[p] === null)
    o[p] = c[p];
    }
    }
    return o;
    }


  • TabPanel.js
    http://tdg-i.com/img/screencasts/2008-04-26_2252.png

    applyIf is working.


  • for now, the OP can delete the attribute before applyIf is called :)


  • Yes, applyIf evaluates the presence of the member (!= undefined).


  • Woah, i see what the OP is talking about.


  • Than, why isn't "activeTab" being copied?


  • Agreed, code modified above.


  • @evant -- That looks a bit dangerous. 'false' and 0 would also pass that ( !o[p] ) test.


  • I would use that revised version with caution. Ext was (and many extensions) designed under the assumption that the 'If' behavior was based on member definition (undefined) not inclusive of a null value. Big difference.

    Eyes open, thats all. ;)


  • Hi,

    Thanks for the modification. The main reason on using Ext.applyIf instead of Ext.apply in component configuration is to let clients override the encapsulated configuration.

    Regards,
    Thiago Souza


  • In the declaration of the TabPanel class:


    activeTab : null


    Since applyIf only checks for undefined, I'm assuming that activeTab already exists for the object.







  • #If you have any other info about this subject , Please add it free.#
    Your name:
    E-mail:
    Telphone:

    Your comments:


    If you have any other info about [2.1] A bug in Ext.applyIf? , Please add it free.

    My rights and duties- employer asks me to provide testimony in its civil lawsuit TU Settlement - Credit Inqury on my credit report