この機能についての私の理解では、WinJS.Application.start()
WinJS が特定の通常のページ初期化イベントをキューに入れ、他のデータを最初にファイルに設定する機会を与えることができdefault.js
ます。start()
の最後で関数を呼び出すことによりdefault.js
、WinJS はキューに入れられたすべてのイベント (イベントなどactivated
) を起動します。
すべてがライフサイクルのどこに当てはまるかを理解しようとしているので、次の例の最初の例が機能するのに 2 番目の例が機能しない理由がわかりません。私がしているのは、ページ タイトルを更新することだけですがapp.start()
、5 秒の遅延後に呼び出すと、期待どおりに動作しません。
まず、次のdefault.html
とおりです。
<html>
<head>
<script references...>
</head>
<body>
<h1 id="pageTitle">Page of coolness...</h1>
</body>
</html>
そして、これが最初のdefault.js
例です(期待どおりに機能します):
(function () {
var app = WinJS.Application;
app.onactivated = function () {
document.getElementById("pageTitle").innerText = "Rock it!";
};
// This code *does* fire the onactivated event:
// The page displays "Rock it!" in the page title
app.start();
})();
2 番目のdefault.js
例を次に示します (期待どおりに動作しません)。
(function () {
var app = WinJS.Application;
app.onactivated = function () {
document.getElementById("pageTitle").innerText = "Rock it!";
};
// This code *doesn't* fire the onactivated event:
// It initially displays "Page of coolness..." in the page title.
// After 5 seconds, it adds "Gettin' there...Almost made it..."
// to the the page title, but "Rock it!" never gets displayed
WinJS.Promise.timeout(5000).then(function () {
document.getElementById("pageTitle").innerText += "Gettin' there...";
app.start();
document.getElementById("pageTitle").innerText += "Almost made it...";
});
})();
app.start()
5 秒の遅延後に呼び出すと、activated
イベントが発生しないのはなぜですか?