From e4166ca60989e7752382e012c1b4f86a12b068a4 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Tue, 6 Aug 2019 14:00:17 +0100 Subject: [PATCH] mediawiki.page.gallery.slideshow: Avoid manual Deferred wrapping MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * Use then(), which automatically forwards errors, instead of manually forwarding fail() to d.reject(). This also ensures that any errors in the done() or fail() handler themselves are caught and reject the returned Deferred – instead of an causing the Deferred to indefinely be in the "pending" state. * Use then(), which makes the code consistently asynchronous, instead of sometimes sync and sometimes async. * Use then() for forward-compat with native ES6 Promise. Change-Id: I58fb6ec23fb4056fe2bbb146ff4225dea9d9f379 --- resources/src/mediawiki.page.gallery.slideshow.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/resources/src/mediawiki.page.gallery.slideshow.js b/resources/src/mediawiki.page.gallery.slideshow.js index 4ea1999de6..667c2ba21b 100644 --- a/resources/src/mediawiki.page.gallery.slideshow.js +++ b/resources/src/mediawiki.page.gallery.slideshow.js @@ -212,7 +212,7 @@ // Make the image smaller in case the current image // size is larger than the original file size. - this.getImageInfo( this.$thumbnail ).done( function ( info ) { + this.getImageInfo( this.$thumbnail ).then( function ( info ) { // NOTE: There will be a jump when resizing the window // because the cache is cleared and this a new network request. if ( @@ -299,9 +299,8 @@ * element once the image has loaded. */ mw.GallerySlideshow.prototype.loadImage = function ( $img ) { - var img, d = $.Deferred(); - - this.getImageInfo( $img ).done( function ( info ) { + return this.getImageInfo( $img ).then( function ( info ) { + var img, d = $.Deferred(); img = new Image(); img.src = info.thumburl; img.onload = function () { @@ -310,11 +309,8 @@ img.onerror = function () { d.reject(); }; - } ).fail( function () { - d.reject(); + return d.promise(); } ); - - return d.promise(); }; /** -- 2.20.1