I am using the WinJS.UI.Pages.render call to load fragments into a page. I read that a page’s ready method can return a promise that completes when the page is ready. I thought that this promise is what would be returned by the WinJS.UI.Pages.render method, but it is not. I was thinking this would be a nice mechanism to asynchronously pass values back from the fragment to the caller.
Is it possible to access the ready promise from the WinJS.UI.Pages.render promise done handler?
Looking at the code in the implementation, it looks like this may actually be a bug in WinJS. The
WinJS.UI.Pages.rendermethod does return a promise, but it’s the one from just afterprocessedis complete and and results in the control instance been returned as the completed promises value.Your best bet is to place an additional promise as a member of your Page class. Then when you get
render, peel off from that promise, rather than therenderpromise itself.It’s important that you use the promise created in the constructor or similar, since the promise returned from
renderis going to complete whenprocessedis called on your page class — before yourreadyreturns, so accessing the value immediately after therendercompletes, yourreadymethod has not yet been called.