mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 02:23:58 +00:00
mw.ViewPageTarget.init: Reduce Deferred clutter in getTarget()
* mw.loader.using returns a promise already. * Use .then() instead of manually forwarding failures. * Cache .promise() result. Change-Id: I3d0a90051c389c02dd5714020b2a1fb872790a18
This commit is contained in:
parent
69750e4b41
commit
7f43fccd4d
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
( function () {
|
||||
var conf, tabMessages, uri, pageExists, viewUri, veEditUri, isViewPage,
|
||||
init, support, getTargetDeferred, enable, userPrefEnabled,
|
||||
init, support, targetPromise, enable, userPrefEnabled,
|
||||
plugins = [];
|
||||
|
||||
/**
|
||||
|
@ -26,11 +26,9 @@
|
|||
* @returns {jQuery.Promise}
|
||||
*/
|
||||
function getTarget() {
|
||||
var loadTargetDeferred;
|
||||
if ( !getTargetDeferred ) {
|
||||
getTargetDeferred = $.Deferred();
|
||||
loadTargetDeferred = $.Deferred()
|
||||
.done( function () {
|
||||
if ( !targetPromise ) {
|
||||
targetPromise = mw.loader.using( 'ext.visualEditor.viewPageTarget' )
|
||||
.then( function () {
|
||||
var target = new ve.init.mw.ViewPageTarget();
|
||||
|
||||
// Tee tracked events to MediaWiki firehose, if available (1.23+).
|
||||
|
@ -46,13 +44,10 @@
|
|||
// Add plugins
|
||||
target.addPlugins( plugins );
|
||||
|
||||
getTargetDeferred.resolve( target );
|
||||
} )
|
||||
.fail( getTargetDeferred.reject );
|
||||
|
||||
mw.loader.using( 'ext.visualEditor.viewPageTarget', loadTargetDeferred.resolve, loadTargetDeferred.reject );
|
||||
return target;
|
||||
} );
|
||||
}
|
||||
return getTargetDeferred.promise();
|
||||
return targetPromise;
|
||||
}
|
||||
|
||||
conf = mw.config.get( 'wgVisualEditorConfig' );
|
||||
|
|
Loading…
Reference in a new issue