Application Packaging Standard

Last updated 18-Mar-2019

onContext

The onContext(context) method is called once the aps.context is received and then every time UX1 receives a notification.

Its input argument context contains the navigation variables available for this view as context.vars.

Note

The onContext method should be used to refresh data displayed on the screen. Since widgets are usually synced with a model, it is sufficient to refresh the model at this phase, for example:

aps.app.model.set("editVPS", getStateful(vps));
aps.apsc.hideLoading();

The aps.apsc.hideLoading() method hides the Loading state from the screen. Call it on completion of asynchronous operations, so that you have all necessary data to display on the screen. In other words, wait for resolving of all deferred promises before calling aps.apsc.hideLoading().

Warning

Do not declare widgets in the onContext method, since a received notification will run this method and thus change data displayed currently on the screen.

For a long-running operation, the onContext method must return a deferred promise and run the aps.apsc.hideLoading() method only after the promise is resolved. For example:

define([
   "dojo/_base/declare",
   "dojo/Deferred",
   "aps/View"
], function (declare, Deferred, View) {
   return declare(View, {
      // ...
      onContext: function() {
         var deferred = new Deferred();
         function longMethod() {
            // ...
            deferred.resolve();
         };
         // ...
         longMethod();
         // ...
         deferred.then(function() {
            aps.apsc.hideLoading();
         });
      },
      ...
});

If navigation variables are declared for the view in the navigation tree, the onContext(context) method receives them in the input argument as the context.vars named list, which is the same as aps.context.vars.

The following example gets the vps variable and then updates the model mapped to widgets:

onContext: function(context) {  // Input parameter contains the ``vars`` object
   self.model.set("vps", context.vars.vps); // View context contains...
                                            //... the "vps" variable defined in meta
   ...
}  // End of onContext
onShow
onHide