Skip to content

Instantly share code, notes, and snippets.

@zxqx
Created March 3, 2015 17:18
Show Gist options
  • Save zxqx/095470e012c1a59341a6 to your computer and use it in GitHub Desktop.
Save zxqx/095470e012c1a59341a6 to your computer and use it in GitHub Desktop.
/**
* Ensure all async action is done before injecting container view
* @param {number} retries
* @return {Promise}
*/
loadContent(retries = 0)
{
var category = this.appConfig.defaultContentCategory;
var logoUrl = this.appConfig.logoUrl;
this.topStreamingViewModel = this.viewModels.create(TopStreamingViewModel);
this.topStreamingViewModel.category = category;
var header = await this.setupHeader(logoUrl);
var content = await this.setupTopStreamingContent(category);
var navBar = await this.setupNavigationBar();
var sidebar = await this.setupSidebar();
.timeout(MAX_FETCH_TIME_ALLOWED)
.then(() => {
this.loadingState.setToReady();
this.views.removeView(this.loadingIndicator);
this.views.addView(this.container);
process.nextTick(() => this.container.fadeIn());
})
.catch((e) => {
if (retries < MAX_NUMBER_OF_RETRIES_ALLOWED) {
this.loadingState.setToRetrying();
return this.loadContent(retries + 1);
}
else {
this.loadingState.setToFailed();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment