Tip: Delay App Loading Until All Data is Ready

Comments

19 comments

  • Avatar
    Alexander Steshenko

    Hello, 

    Does

    initialState: 'loading', 

    have any effect actually? In this example.

     

    Thanks,

    Alex.

  • Avatar
    James A. Rosen

    If you set an initialState on an App, the app will transition to that template when it first loads. For more information, see the Templates docs.

  • Avatar
    Alexander Steshenko

    Okay, thanks.

     For more information, see the  Templates docs.

    No mention of "initialState" there though.

  • Avatar
    Karim Dibo

    Hi,

    I'd like my app to behave differently on activation depending on whether a custom_field is filled or not.

    Problem is I don't know if the field is empty or just not loaded yet. Do you have an idea how i could?

    Thanks

    Karim

  • Avatar
    James A. Rosen

    Karim: that one is going to be tricky with the current framework behavior. The problem is that if you use a custom\_field\_12345.changed callback to trigger your behavior, it will only ever fire if the field is filled in. Would it be possible to perform the not-filled-in behavior at first, then switch when (and if) the field is populated?

    We do want to change the framework to delay app.activated until all the data is ready, but we don't have an ETA for that change yet.

  • Avatar
    Karim Dibo

    "perform the not-filled-in behavior at first, then switch when (and if) the field is populated"

    Thanks. This is how I'll do it for now.

  • Avatar
    Gee C

    The ticket events don't seem to be working for us.  The 'app.activated' works fine and some DOM events work fine as well, the ticket events never seem to fire.  For example,

    events: { 'app.activated': 'renderPage', 'ticket.requester.id.changed': 'renderPage', 'ticket.subject.changed': 'renderPage' },

    It never calls renderPage when the ticket is done loading.  Any ideas?

  • Avatar
    Kristine

    I'm having the same problem as Gee.  My code is as follows:

        events: {
          'app.activated': 'waitForData',
          'ticket.requester.email.changed': 'waitForData'
        }, //end events

        waitForData: function() {
          if (debug) console.log('app activated');
          var requesterEmail = this.ticket().requester().email();
          if ( requesterEmail == null ) {
            if (debug) console.log('waiting for data');
            return;
          }
          if (debug) console.log('changing');
          this.switchTo('init', {
            requesterEmail: requesterEmail
          });
        }

    The last thing my web console prints is 'waiting for data.'  I know the requester email data is loaded at some point because I can print it to the console using events in other apps (such as when a custom field value changes).  I can only assume that the 'ticket.requester.email.changed' event is not registering.  Any ideas?

  • Avatar
    James A. Rosen

    Yes, the problem is that you're asking for this.ticket().requester().email() , but the Requester is null until the data is ready. This causes a null-pointer exception, which stops the app from loading. We will fix the framework to delay loading apps until all the data is ready, but for now you'll have to guard against this problem.

  • Avatar
    Kristine

    Thanks James.  I'll just combine this with my other event detection app for now.

  • Avatar
    John Hanlon

    Is there a ballpark timeline on when we can expect to see the changes made delay the triggering of app.activated?

  • Avatar
    Maxime

    we are working on this as we speak. expect some news soon !

  • Avatar
    Matthieu Gross

    Hi James,

    We still have this problem. Wouldn't be better to have a different event like 'data.loaded'?

  • Avatar
    Maxime

    Hi Mathieu

    We are actually working on this "bug" right now, so i'll have some good news soon hopefully! i'll be sure to update this thread

  • Avatar
    KK

    when can we expect any news?

  • Avatar
    Maxime

    Hi KK

    Hopefully this should go out next week, i'll make sure to update this thread when it does!

    Max

  • Avatar
    Maxime

    Hi KK

    The app.activated behavior is now fixed, we will load all fields and their values for system fields (standard zendesk fields like assignee, CCs, type, priority etc...) and then fire app.activated.

    After that the custom fields will load. 

    Hope this helps

    Maxime

  • Avatar
    Matthieu Gross

    Hi Maxime,

    This partially helps. Why not to fire app.activated after ALL fields & values are loaded (custom fields included)?

    By the way I noticed recently that "this.ticket().collaborators()[0].role()" looks not aways loaded (?). It looks like I have to open the user page to see its role (or run a specific AJAX request). Any idea why I got that?

     

Please sign in to leave a comment.

Powered by Zendesk