locked
Using require() inside a WinJS.UI.Pages.ready method

    Question

  • I am using requirejs in my WinJS app and also use WinJS.UI.Pages. I understand that all the Pages methods are supposed to return a promise or nothing.

    WinJS.UI.Pages.define("/pages/fileOpenPicker.html", {
      ready: function (element, options) {
        require(["log"], function (log) {
        });
      }
    });

    The ready call is returned immediately, since require works asynchronously. I assume if I return a Promise here the page would wait for the promise to finish and not be displayed. So the way I do it now is actually better, since the page is displayed but only when require calls my callback I fill the page with useful data.

    Opinions?

    Friday, March 21, 2014 10:15 PM

Answers

  • Your approach sounds okay. The ready event gets triggered when your UI is ready, so calling require(...) from ready triggers another asynchronous function to execute - which when complete should already have the UI elements ready to be used.

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

    Saturday, March 22, 2014 12:55 AM
    Moderator

All replies

  • Your approach sounds okay. The ready event gets triggered when your UI is ready, so calling require(...) from ready triggers another asynchronous function to execute - which when complete should already have the UI elements ready to be used.

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

    Saturday, March 22, 2014 12:55 AM
    Moderator
  • Thanks Prashant for your help here in the forums. With 1 year absence from WinJS I have to catch up a little. And even more so now that I discovered the beauty of requirejs ;)
    Saturday, March 22, 2014 1:03 AM