Deferring Events with Promises

WinJS.Application events are different than normal DOM events because they support promises. You can execute an asynchronous task during a WinJS.Application event and delay the next event until a promise completes.

For example, the default.js file created when you create a new Windows Store app project delays the completion of the WinJS.Application.activated event until the asynchronous call to WinJS.UI.processAll() completes. This ensures that all of the controls in the page are processed before the splash screen is torn down.

Here’s what the WinJS.Application.activated event handler looks like in the default.js file with some code removed:

app.onactivated = function (args) {    

Get Windows® 8.1 Apps with HTML5 and JavaScript Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.