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

Thread: Is config really working in Ext or not?

  1. #1
    Sencha Premium User bluehipy's Avatar
    Join Date
    Mar 2010
    Location
    Romania
    Posts
    628
    Answers
    67

    Default Is config really working in Ext or not?

    A simple test case:
    Ext.define('ClassA',{
    xtype:'xa',
    config:{
    prop:{p:'A'}
    }
    });




    Ext.define('ClassB',{
    xtype:'xb',
    extend:'ClassA',
    config:{
    prop:{p:'B'}
    }
    });


    var
    a = new ClassA(),
    b = new ClassB();

    console.log(a.prop, b.prop); // Object {p: "A"} Object {p: "A"}

    console.log(a.getProp(), b.getProp()); //Object {p: "A"} objectClass {p: "B"}
    console.log(a.getProp(), b.getProp()); //Object {p: "A"} objectClass {p: "B"}
    console.log(a.prop, b.prop); // Object {p: "A"} objectClass {p: "B"}

    a = Ext.create('ClassA',{prop:1});
    b = Ext.create('ClassB',{config:{prop:2}});

    console.log(a.prop, b.prop); // Object {p: "A"} Object {p: "A"}

    console.log(a.getProp(), b.getProp()); //Object {p: "A"} objectClass {p: "B"}
    console.log(a.getProp(), b.getProp()); // Object {p: "A"} objectClass {p: "B"}
    console.log(a.prop, b.prop); // Object {p: "A"} objectClass {p: "B"}

    a.setProp(3);
    b.setProp(4);

    console.log(a.prop, b.prop); //3 4
    console.log(a.getProp(), b.getProp());// 3 4
    console.log(a.getProp(), b.getProp()); // 3 4
    console.log(a.prop, b.prop); // 3 4

    Tried with 4.2.1

    My conclusion is that config is mot working by anychance as expected and there is no elegant way to override a previously defined config property.
    Latest thoughts on the subject: http://joy2share.com/senchatouch/

  2. #2
    Sencha Premium User
    Join Date
    Nov 2010
    Location
    Chicago
    Posts
    2,372
    Answers
    20

    Default

    This is not supported

  3. #3
    Sencha Premium User bluehipy's Avatar
    Join Date
    Mar 2010
    Location
    Romania
    Posts
    628
    Answers
    67

    Default

    Well... this is a BIG minus for Ext.
    Latest thoughts on the subject: http://joy2share.com/senchatouch/

  4. #4
    Sencha Premium Member
    Join Date
    Feb 2012
    Location
    Raleigh, NC
    Posts
    448
    Answers
    23

    Default

    The default constructor in Ext.Base doesn't automatically trigger an initConfig(). So all you should need to do is define a constructor, modify this.config if necessary, and call initConfig(). https://fiddle.sencha.com/#fiddle/4cv

  5. #5
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,256
    Answers
    759

    Default

    That's not the case. The ticket @LesJ is referring to is specifically using the override keyword.

    As @brian428 mentioned, OP needs to call initConfig in the constructor.
    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.

  6. #6
    Sencha Premium User
    Join Date
    Nov 2010
    Location
    Chicago
    Posts
    2,372
    Answers
    20

    Default

    Quote Originally Posted by evant View Post
    That's not the case. The ticket @LesJ is referring to is specifically using the override keyword.

    As @brian428 mentioned, OP needs to call initConfig in the constructor.

    Thanks for the correction brian428 and evant.

  7. #7
    Sencha Premium User bluehipy's Avatar
    Join Date
    Mar 2010
    Location
    Romania
    Posts
    628
    Answers
    67

    Default

    I figured out that the initCOnfig is not called.
    How so ever there is a problem in offering the correct config.

    At the construction time you have a this.config that is classify, as in it being a class rather than an object. There is the config object as n the constructor argument. My guess is that you have to mere the two to get the expected result. Also you have to reset the initialized internals to get the applyers applied.


    PHP Code:
    function constructor(config){
        var 
    me this;
     
        
    //building config
        
    var cfg Ext.Object.merge({}, me.configMap),
        
    configNameCache Ext.Class.configNameCache;
            

        
    Ext.Object.each(me.configMap, function(propNamepropValue){
            if(
    typeof(me[propName]) !== 'undefined'){
                
    // force applyers call
                
    me[configNameCache[propName].initialized] = false;
            }
        });

        
    cfg = {};

        for(var 
    o in me.config){
            
    cfg[o] = me.config[o];
        }

        for(var 
    o in config){
            if(
    typeof(config[o]) != 'undefined'){
                
    cfg[o] = config[o];
            }
        }

        
    me.initConfig(cfg);

        return 
    me.callParent(arguments);

    Latest thoughts on the subject: http://joy2share.com/senchatouch/

  8. #8
    Sencha Premium Member
    Join Date
    Feb 2012
    Location
    Raleigh, NC
    Posts
    448
    Answers
    23

    Default

    You're right that you can merge the constructor config with the class-level config (using Ext.apply() or Ext.merge()). But I'm really not sure about the rest of what you're saying. As my Fiddle shows, all you need to do is call initConfig(). I do this all the time and have never had any issues, nor have I had to do anything like what you're showing in your code.

  9. #9
    Sencha Premium User bluehipy's Avatar
    Join Date
    Mar 2010
    Location
    Romania
    Posts
    628
    Answers
    67

    Default

    Hmm... surprisingly you are right. I was adding all that uglyness because in some context applyers were not called.... how so ever I checked now again and things are happening actually....I have to see if I don't run in any static link or other problems by just by calling initCnfig with the merge between config and this.config but it seams correct Thanks.
    Latest thoughts on the subject: http://joy2share.com/senchatouch/

  10. #10
    Sencha Premium Member
    Join Date
    Feb 2012
    Location
    Raleigh, NC
    Posts
    448
    Answers
    23

    Default

    Quote Originally Posted by evant View Post
    As @brian428 mentioned, OP needs to call initConfig in the constructor.
    Evant, as an aside, is there actually a reason that Sencha doesn't include a call to initConfig() in the Base constructor? Seems like that would solve all sorts of problems?

Page 1 of 2 12 LastLast

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
  •