locked
require-js prevents WinJS.Application.onactivated to be called RRS feed

  • Question

  • In this example: http://1drv.ms/1oGzKGr I try to use requirejs with WinJS.

    I want my app.js (default.js) to depend on "log" so I write

    (function () {
      "use strict";
    
      var app = WinJS.Application;
      var activation = Windows.ApplicationModel.Activation;
    
      require(["log"], function (log) {
        var logger = log.logger("app");
    
        app.onactivated = function (args) {
          if (args.detail.kind === activation.ActivationKind.launch) {
            if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
            } else {
            }
            args.setPromise(WinJS.UI.processAll());
          }
        };
    
        app.oncheckpoint = function (args) {
        };
    
        app.start();
      });
    })();

    The onactivated handler is never called though.


    • Edited by pkursawe Friday, March 21, 2014 7:55 PM
    Friday, March 21, 2014 7:54 PM

Answers

  • The problem here is that the call to app.start() is nested inside the completion of require(...), so by the time require(...) completes the caller (anonymous function) has already completed.

    Since app.start() is not executed, you won't see the "app" events, so move out the app.start() outside the completion of the require and move it to the anonymous function like this:

    (function() {
        ...
        app.oncheckpoint = function (args) {
          //...
        };    
      });
      app.start();
    })();
    


    Windows Store Developer Solutions, follow us on Twitter: @WSDevSol|| Want more solutions? See our blog

    Saturday, March 22, 2014 12:26 AM
    Moderator