1. #1
    Sencha Premium Member
    Join Date
    Oct 2011
    Location
    Duluth, MN
    Posts
    126
    Vote Rating
    4
    Answers
    2
    badgerb1 is on a distinguished road

      0  

    Default Unanswered: Touch 2.1 Constructor change?

    Unanswered: Touch 2.1 Constructor change?


    Hi all,

    I've been attempting to upgrade from 2.0 to 2.1 and am running into quite a few problems, mostly they are working out with small changes. One seemingly strange and dangerous change though is the new way constructors are handled.

    It seems a constructor can now return a value instead of just finish instantiating the object that is being constructed. Just wondering what the best way would be to handle extending and overriding classes now?

    I.E. used to do this.
    Ext.define('addToSomething', {
    extend:'Ext.Something',
    ....
    constructor: function(config){
    this.doSomePreprocessing();
    this.callParent(arguments);
    this.doSomeProcessing();

    }

    Now, since the parent constructor may return a value that is not "this" we have to do something like this I think.
    Ext.define('addToSomething', {
    extend:'Ext.Something',
    ....
    constructor: function(config){
    config = this.doSomePreProcessing();
    var newThis = this.callParent(arguments) || this;
    newThis.doSomeProcessing();
    return newThis;
    }

    I don't actually think this will work in the end though since newThis could be a completely different thing, and wouldn't contain any of the extension properties. Touch Grid actually uses this "feature" to return a List implementation instead of a dataview implementation so our extension class isn't used.

    Anyway, thought this should be documented somewhere, and I couldn't find it.

    Thanks
    Bob

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,549
    Vote Rating
    873
    Answers
    3567
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Touch grid does it and logs out that you shouldn't use it.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha Premium Member
    Join Date
    Oct 2011
    Location
    Duluth, MN
    Posts
    126
    Vote Rating
    4
    Answers
    2
    badgerb1 is on a distinguished road

      0  

    Default


    Yeah that was the second place we saw it and other than rewriting our extension entirely (it allows you to specify editor components that are always shown instead of having to click on them) it won't work with the new structure and winds up crashing because a List is returned instead of a Dataview and that List doesn't have any of the custom extension code of course.

    The weird one is Model. It seems that model can return a cached version which for some reason didn't break in 2.0 but when we switched to 2.1 all of our models that have some kind of special constructor didn't work anymore and I had to use the mechanism above to get things working. I just noticed that the actual code is the same in 2.0 vs 2.1 so it's not really a change to the constructor, it's just that now it seems to matter in 2.1.

    Thanks
    Bob

Thread Participants: 1