Last active
August 29, 2015 14:09
-
-
Save zxqx/295911a403ec84ca8dba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Display loading indicator while view model data is being synced | |
* Set up container view and its subviews | |
* Fade in container | |
* @return {Promise} | |
*/ | |
StreamController.prototype.start = function() | |
{ | |
this.container = this.setupCommunityStream(); | |
this.loadingIndicator = this.setupLoadingIndicator(); | |
this.views.addView(this.loadingIndicator); | |
this.setupHeader(); | |
this.setupNavigationBar(); | |
this.fetchAsyncContent(); | |
}; | |
/** | |
* Ensure all async action is done before injecting container view | |
* @param {number} retries | |
*/ | |
StreamController.prototype.fetchAsyncContent = function(retries) | |
{ | |
retries = retries || 0; | |
var _this = this; | |
return Promise.all([ | |
this.setupTopStreaming(), | |
this.setupSidebar() | |
]) | |
.timeout(MAX_FETCH_TIME_ALLOWED) | |
.then(function() { | |
_this.views.removeView(_this.loadingIndicator); | |
_this.views.addView(_this.container); | |
process.nextTick(function() { | |
_this.container.fadeIn(); | |
}); | |
}) | |
.catch(function(e) { | |
if (retries < 3) { | |
_this.loadingIndicator.model.setAsRetrying(); | |
return _this.fetchAsyncContent(retries + 1); | |
} | |
else { | |
_this.loadingIndicator.model.setAsFailed(); | |
_this.loadingIndicator.hideSpinner(); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment