Merge "Allow ve.init.Platforms to asynchronously initialize themselves"

This commit is contained in:
jenkins-bot 2013-12-17 21:15:29 +00:00 committed by Gerrit Code Review
commit 0a5687e296
2 changed files with 28 additions and 0 deletions

View file

@ -244,6 +244,8 @@ ve.init.mw.Target.onModulesReady = function () {
}
// Dereference the callbacks
this.pluginCallbacks = [];
// Add the platform promise to the list
promises.push( ve.init.platform.getInitializedPromise() );
// Create a master promise tracking all the promises we got, and wait for it
// to be resolved
$.when.apply( $, promises ).done( this.modulesReady.resolve ).fail( this.modulesReady.reject );

View file

@ -127,3 +127,29 @@ ve.init.Platform.prototype.getUserLanguages = function () {
ve.init.Platform.prototype.getMediaSources = function () {
throw new Error( 've.init.Platform.getMediaSources must be overridden in subclass' );
};
/**
* Initialize the platform. The default implementation is to do nothing and return a resolved
* promise. Subclasses should override this if they have asynchronous initialization work to do.
*
* External callers should not call this. Instead, call #getInitializedPromise.
*
* @private
* @returns {jQuery.Promise} Promise that will be resolved once initialization is done
*/
ve.init.Platform.prototype.initialize = function () {
return $.Deferred().resolve().promise();
};
/**
* Get a promise to track when the platform has initialized. The platform won't be ready for use
* until this promise is resolved.
*
* @returns {jQuery.Promise} Promise that will be resolved once the platform is ready
*/
ve.init.Platform.prototype.getInitializedPromise = function () {
if ( !this.initialized ) {
this.initialized = this.initialize();
}
return this.initialized;
};