Krinkle has uploaded a new change for review. https://gerrit.wikimedia.org/r/145552
Change subject: special.js: Use then() instead of manually wrapping Deferred ...................................................................... special.js: Use then() instead of manually wrapping Deferred * No need for the 'new' operator in $.Deferred. It's not an instantiable constructor with prototype but an object factory. Unnecessary overhead and didn't match code used elsewhere. * Simplifies data processing to receiving data and returning the transformed value. No need to invoke a shared interface like d.resolve or d.reject. Follows-up 76b57a8, 6ff803c. Change-Id: Ie1887c9d8b31c19fef24acbc1cc4be1194930217 --- M js/ext.urlShortener.special.js 1 file changed, 9 insertions(+), 13 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UrlShortener refs/changes/52/145552/1 diff --git a/js/ext.urlShortener.special.js b/js/ext.urlShortener.special.js index 1c70b05..f1e53fd 100644 --- a/js/ext.urlShortener.special.js +++ b/js/ext.urlShortener.special.js @@ -65,22 +65,18 @@ * fails with an error object on failure */ UrlShortener.prototype.shortenUrl = function ( url ) { - var d = new $.Deferred(), - validate = this.validateInput( url ); - if ( validate === true ) { - this.api.get( { + var validate = this.validateInput( url ); + if ( validate !== true ) { + return $.Deferred().reject( validate ).promise(); + } + return this.api.get( { action: 'shortenurl', url: url - } ).done( function ( data ) { - d.resolve( data.shortenurl.shorturl ); - } ).fail( function ( errCode, data ) { - d.reject( data.error ); + } ).then( function ( data ) { + return data.shortenurl.shorturl; + }, function ( errCode, data ) { + return data.error; } ); - - } else { - d.reject( validate ); - } - return d.promise(); }; /** -- To view, visit https://gerrit.wikimedia.org/r/145552 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ie1887c9d8b31c19fef24acbc1cc4be1194930217 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/UrlShortener Gerrit-Branch: master Gerrit-Owner: Krinkle <krinklem...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits