IndexedDB、Web SQL、またはWeb Storageを使用して、クライアントにデータを保存しています (または、クライアントがストレージをサポートしていない場合は AJAX にフォールバックします)。ページが読み込まれると、ストアからのデータを表示したいと思います。しかし、ストアの準備ができていない可能性があるため、DOM の準備ができているときにデータを表示できません。DOM の準備ができていない可能性があるため、ストアの準備ができているときにデータを表示できません。
明らかに、dom と store によって設定されたフラグをチェックする条件を実装することも、タイムアウトを使用することもできますが、それはずさんなようです (また、2 つ以上の条件が満たされる必要がある場合はうまくスケーリングされません)。この状況を処理するための一般的に「良い」方法はありますか? クロスブラウザー ソリューションを希望します (たとえば、動作しwatch
ません)。
状況の例:
// FooServiceFactory decides which storage method to use based on
// what the browser allows and returns a new instance of the
// implementation and starts initializing resources.
var fooService = FooServiceFactory.getInstance();
// DOM is ready
window.onload = function() {
// fooService may not be ready yet depending on whether
// storage has already been setup or if resources need to
// be retrieved from the server. But I don't want this calling
// JS to know about that.
fooService.getAllFoo(request, function(response, status) {
// do something with response
});
};
注:私は今のところ自分の答えを受け入れましたが、これを処理するより良い方法をまだ開いています.