23.01.2018 Views

MICROSOFT_PRESS_EBOOK_PROGRAMMING_WINDOWS_8_APPS_WITH_HTML_CSS_AND_JAVASCRIPT_PDF

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 16<br />

WinRT Components: An<br />

Introduction<br />

At the very beginning of this book, in the first two pages of Chapter 1, “The Life Story of a Windows<br />

Store App,” we learned that apps can be written in a variety of languages and presentation<br />

technologies. For the better part of this book we’ve spoken of this as a somewhat singular choice: you<br />

choose the model that best suits your experience and the needs of your app and go from there.<br />

At the same time, we’ve occasionally encountered situations where some sort of mixed language<br />

approach is possible, even necessary. In Chapter 1, in “Sidebar: Mixed Language Apps,” I introduced the<br />

idea that an app can actually be written in multiple languages. In Chapter 8, “State, Settings, Files, and<br />

Documents,” I mentioned that gaining access to database APIs beyond IndexedDB could be<br />

accomplished with a WinRT component. In Chapter 10, “Media,” we saw that JavaScript might not<br />

necessarily the best language in which to implement a pixel crunching routine. And in Chapter 13, “Tiles,<br />

Notifications, the Lock Screen, and Background Tasks” we encountered the Notifications Extensions<br />

Library, a very useful piece of code written in C# that made the job of constructing an XML payload<br />

much easier from JavaScript. We also saw that background tasks can be written in languages that differ<br />

from that of the main app.<br />

With the primary restriction that an app that uses <strong>HTML</strong> and <strong>CSS</strong> for its presentation layer cannot<br />

share a drawing surface with WinRT components written in other languages, the design of WinRT really<br />

makes the mixed language approach possible. As discussed in Chapter 1, WinRT components written in<br />

any language are made available to other languages through a projection layer that translates the<br />

component’s interface into what’s natural in the target language. All of WinRT is written this way, and<br />

custom WinRT components take advantage of the same mechanism. (We’ll see the core characteristics<br />

of the JavaScript projection later in this chapter.)<br />

What this means for you—writing an app with <strong>HTML</strong>, <strong>CSS</strong>, and JavaScript—is that you can<br />

implement various parts of your app in a language that’s best suited to the task or technically necessary.<br />

As a dynamic language, JavaScript shows its strength in easily gluing together functionality provided by<br />

other components that do the heavy lifting for certain kinds of tasks (like camera capture, background<br />

transfers, etc.). Those heavy-lifting components are often best written in other language such as C++,<br />

where the compiled code runs straight on the CPU instead of going through runtime layers like<br />

JavaScript.<br />

716

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!