Yurik has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/374101 )
Change subject: Simplify getExamples/getLabels, rm $.deferred() ...................................................................... Simplify getExamples/getLabels, rm $.deferred() Promises are much cleaner without the deferred() method, easier to follow the code, and ES6 introduces much cleaner syntax to work with them still. BTW, we really ought to switch the code to ES6 (classes, async, ...), and use Babel for compatibility until ES6 support is mandatory. Change-Id: I218a734b5986b00c0331a9561ff70f8ab6efd263 --- M wikibase/queryService/api/QuerySamples.js M wikibase/queryService/ui/QueryExampleDialog.js 2 files changed, 14 insertions(+), 30 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/wikidata/query/gui refs/changes/01/374101/1 diff --git a/wikibase/queryService/api/QuerySamples.js b/wikibase/queryService/api/QuerySamples.js index 254bc07..d852305 100644 --- a/wikibase/queryService/api/QuerySamples.js +++ b/wikibase/queryService/api/QuerySamples.js @@ -34,31 +34,20 @@ * @return {jQuery.Promise} Object taking list of example queries { title:, query: } */ SELF.prototype.getExamples = function () { - var deferred = $.Deferred(), - self = this; + var self = this; - $.ajax( { + return $.ajax( { url: API_ENDPOINT + encodeURIComponent( PAGE_TITLE + '/' + self._language ) + '?redirect=false', dataType: 'html' - } ).done( - function ( data ) { - deferred.resolve( self._parseHTML( data ) ); - } - ).fail( - function() { - // retry without language - $.ajax( { - url: API_ENDPOINT + encodeURIComponent( PAGE_TITLE ) + '?redirect=false', - dataType: 'html' - } ).done( - function ( data ) { - deferred.resolve( self._parseHTML( data ) ); - } - ); - } - ); - - return deferred; + } ).catch( function() { + // retry without language + return $.ajax( { + url: API_ENDPOINT + encodeURIComponent( PAGE_TITLE ) + '?redirect=false', + dataType: 'html' + } ) + } ).then( function ( data ) { + return self._parseHTML( data ); + } ); }; /** diff --git a/wikibase/queryService/ui/QueryExampleDialog.js b/wikibase/queryService/ui/QueryExampleDialog.js index 816cc34..9ec16e6 100644 --- a/wikibase/queryService/ui/QueryExampleDialog.js +++ b/wikibase/queryService/ui/QueryExampleDialog.js @@ -244,19 +244,14 @@ return 0; } ).slice( 0, 50 ); - var deferred = $.Deferred(); - this._wikibaseApi.getLabels( tagCloud.map( function ( v ) { + return this._wikibaseApi.getLabels( tagCloud.map( function ( v ) { return v.id; - } ) ).done( function ( data ) { + } ) ).then( function ( data ) { tagCloud.forEach( function ( tag ) { tag.label = _.compact( data.entities[tag.id].labels )[0].value; - } ); - - deferred.resolve( tagCloud ); + return tagCloud; } ); - - return deferred.promise(); }; /** -- To view, visit https://gerrit.wikimedia.org/r/374101 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I218a734b5986b00c0331a9561ff70f8ab6efd263 Gerrit-PatchSet: 1 Gerrit-Project: wikidata/query/gui Gerrit-Branch: master Gerrit-Owner: Yurik <yuriastrak...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits