mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-09-24 18:58:42 +00:00
Merge "Allow ve.init.Platforms to asynchronously initialize themselves"
This commit is contained in:
commit
0a5687e296
|
@ -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 );
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue