23.01.2018 Views

MICROSOFT_PRESS_EBOOK_PROGRAMMING_WINDOWS_8_APPS_WITH_HTML_CSS_AND_JAVASCRIPT_PDF

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

• WinRT APIs sometimes return Int64 types (alone or in structs) for which there is no equivalent<br />

in JavaScript. The 64-bit type is preserved in JavaScript, however, so you can pass it back to<br />

WinRT in other calls. However, if you modify the variable holding that value, even with<br />

something as simple as a ++ operator, it will be converted into a JavaScript Number. Such a value<br />

will not be accepted by methods expecting an Int64.<br />

• If a component method provides multiple output parameters, these show up in JavaScript as an<br />

object with those different values. There is no clear standard for this in JavaScript; it’s best to<br />

avoid in component design altogether.<br />

The bottom line is that the projection layer tries to make WinRT components written in any other<br />

language look and feel like they belong in JavaScript, without introducing too much overhead.<br />

Scenarios for WinRT Components<br />

Earlier in the “Choosing a Mixed Language Approach” section I briefly outlined a number of scenarios<br />

where WinRT components might be very helpful in the implementation of your app. In this section we’ll<br />

think about these scenarios a little more deeply, and I’ll point you to demonstrations of these scenarios<br />

in the samples, where such are available.<br />

Higher Performance<br />

Increasing the performance of a Windows Store app written in <strong>HTML</strong>, <strong>CSS</strong>, and JavaScript is one of the<br />

primary scenarios for offloading some work to a WinRT component.<br />

When evaluating the performance of your app, keep an eye open for specific areas that are<br />

computationally intensive or involve moving a lot of data around. For example, if you found it necessary<br />

to implement an extended splash screen for those exact reasons, perhaps you can reduce the time the<br />

user has to wait (especially on first launch) before the app is active. Any other situation where the user<br />

might have to wait—while they might have anything better to do than watch a progress indicator!—is a<br />

great place to use a high performance component if possible. Clearly there are scenarios where the<br />

performance of the app isn’t so much the issue as is network latency, but once you get data back from a<br />

service you might be able to pre-process it faster in a component than in JavaScript.<br />

Another great place to insert a high-performance component is in an app’s startup sequence,<br />

especially if it has extra work to do on first run. For example, an app package might include large<br />

amounts of compressed data to minimize the size of its download from the Store, but it needs to<br />

decompress that data on first run. A WinRT component might significantly shorten that initialization<br />

time. If the component uses WinRT APIs to write to your app data folders, all that data will also be<br />

accessible from JavaScript through those same APIs.<br />

748

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

Saved successfully!

Ooh no, something went wrong!