Question

What is the distinction between Windows.UI.WebUI.WebUIApplication versus WinJS.Application?

WinJS.Application is a namespace. WebUIApplication is an object (or a class of object). But consider the following:

WebUIApplication supports the following events: WebUIApplication.activated WebUIApplication.resuming WebUIApplication.suspending WebUIApplication.navigated

WinJS.Application Namespace defines the following events: onactivated oncheckpoint onerror onloaded onready onsettings onunload

In particular, why is resuming done with WebUIApplication but not with WinJS.Application, but it seems that activation and checkpoint can be done either way?

Windows.UI.WebUI.WebUIApplication.onresuming = function (args) { ... }; // OK

WinJS.Application.oncheckpoint = function (args) { ... }; // OK

WinJS.Application.onactivated  = function (args) { ... }; // OK

WinJS.Application.onresuming  = function (args) { ... }; // NOT OK
Was it helpful?

Solution

The APIs you refer to that are in the Windows.* namespace are the actual core of the app model. Everything in WinJS, on the other hand, are wrappers that are intended to simplify that app model where there is value in doing so. For example, most apps need to do some work on the suspending event, and WinJS provides a sessionState object that is automatically saved on suspended and reloaded when the app is relaunched. However, because there's typically no action that WinJS needs to do for resuming, it doesn't wrap that particular event.

The Windows.* (WinRT) APIs, in other words, are the essential core that you have to use to write an app. WinJS is an optional library that is not at all required, but contains many essentials (like controls) that most apps will use anyway.

Typically, then, you'll use the WinJS events for convenience. It's also easy to include resuming in this model: add a handler for the WebUIApplication.oneresuming event, and call WinJS.Application.queueEvent("resuming", ...) which will then route a "resuming" event into the WinJS.Application object. That way you can centralize your handling of application events in one place.

I talk more of the relationship between these in Chapter 3 of my free ebook, Programming Windows Store Apps in HTML, CSS, and JavaScript, Second Edition, currently in preview. See http://aka.ms/BrockschmidtBook2.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top