1. #1
    Sencha User
    Join Date
    Oct 2012
    Posts
    27
    Answers
    2
    Vote Rating
    1
    English is on a distinguished road

      0  

    Default Unanswered: Destroy View, Controller Errors Because the View is Gone. (MVC)

    Unanswered: Destroy View, Controller Errors Because the View is Gone. (MVC)


    I'm assuming I'm not adhering to the best practice here. Here's my scenario:

    I have a container view, which contains a few views concerning login (login, forgot password, support, etc...).

    Upon successful login, I destroy this container view to conserve resouces.
    The trouble I'm getting is that the controller for these views still exist. The controller is throwing an error because (obviously), it can't find the view in the application.

    What's the best practice here?

  2. #2
    Sencha User
    Join Date
    Oct 2012
    Posts
    27
    Answers
    2
    Vote Rating
    1
    English is on a distinguished road

      0  

    Default


    Some more info:
    What's happening is that, inside the controller, I have a function (called on the related view show event), which translates the page. This event seems to be being fired at any time after the view is destroyed.

    Currently, I've added a check at the beginning of the function, which checks for the existence of the view, else returns.

    Code:
    TranslatePage: function(){
       if(!Ext.getCmp('LoginForm')) return;
       ...
    }
    This still seems like a hack to me. Does anybody know of a better way?

  3. #3
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    35,673
    Answers
    3355
    Vote Rating
    748
    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


    What event is being fired to execute TranslatePage (even if it's executed within another event listener)
    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.

  4. #4
    Sencha User
    Join Date
    Oct 2012
    Posts
    27
    Answers
    2
    Vote Rating
    1
    English is on a distinguished road

      0  

    Default


    Thanks, Mitch.

    For the pages in question, I have a controller for each view. The controller is listening to the "show" event.

    On the show event, I'm calling a function to translate the page:

    Code:
        TranslatePage: function(){
            //Get the language translations for this page.
            var Language=localStorage.getItem('venulang');
            if(!Language) Language="en_utf8";
            var codes=new Array();
            //######################################Enter your translations here#############################################
            codes.push('back');
            codes.push('forgotpassword');
            codes.push('troubleloggingin');
            codes.push('resetpassword');
            codes.push('entertheemail');
            codes.push('email');
            codes.push('pleaseenteravalid');
            codes.push('formerror');
            //######################################End of translations######################################################
            codes=codes.join(",");
            Ext.Ajax.request({
                method: 'POST',
                url: 'GetLanguageStrings.php?lang='+Language,
                params: {
                    file: 'mobile',
                    keys: codes
                },
                scope: this,
                success: function(response){
                    if(!this.getForgotPassword()) return; //Necessary hack because Sencha fires a "show" event when the view is destroyed.
                    this.setTranslations(Ext.JSON.decode(response.responseText));
                    //Translate the page
                    this.getTitleBar().setTitle(this.getTranslations()['forgotpassword']);
                    this.getFieldset().setTitle(this.getTranslations()['troubleloggingin']);
                    this.getFieldset().setInstructions(this.getTranslations()['entertheemail']);
                    this.getFieldset().down('textfield').setLabel(this.getTranslations()['email']);
                    this.getForgotPassword().down('button[action="ResetPassword"]').setText(this.getTranslations()['resetpassword']);
                    this.getTitleBar().down('button[action="ResetBack"]').setText(this.getTranslations()['back']);
                },
                failure: function(){
                    console.log('Failure');
                }
            });
        }
    I have highlighted the "hack" in red. It seems that Sencha fires a "show" event when the view is destroyed.

    Although this works, I'm just wondering if, on a high level, this is the best way to do things when "cleaning up" by destroying un-needed views. This is something that will be happening often.

  5. #5
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    35,673
    Answers
    3355
    Vote Rating
    748
    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


    When a component is destroyed it is first hidden and the layout fires a show event before it's hidden which is the cause of this.
    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.

  6. #6
    Sencha User
    Join Date
    Oct 2012
    Posts
    27
    Answers
    2
    Vote Rating
    1
    English is on a distinguished road

      0  

    Default


    Yes. I realised this. Hence the hack. My question was whether this is the best way to conserve resources (by destroying un-needed components).

    Also, we're ignoring the elephant in the room. Why on earth does Sencha fire a show event when a component is hidden?

Thread Participants: 1

Tags for this Thread

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar