From 15f41fa72803d4ea6cde1fd4508df53338212f62 Mon Sep 17 00:00:00 2001 From: David Lynch Date: Wed, 11 Nov 2015 14:54:53 -0800 Subject: [PATCH] TitleSearchWidget: Use OO.ui.mixin.RequestManager Get that request management goodness that only LookupWidgets used to benefit from. We can undo the earlier hacky fix to avoid requests overrunning each other as part of this. Bug: T114175 Change-Id: I6ff686b3b157d23ff534357ce25ebcb4ef7efea1 --- .../mw.widgets.TitleSearchWidget.js | 34 +++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/resources/src/mediawiki.widgets/mw.widgets.TitleSearchWidget.js b/resources/src/mediawiki.widgets/mw.widgets.TitleSearchWidget.js index 546fbf8f87..96f95491eb 100644 --- a/resources/src/mediawiki.widgets/mw.widgets.TitleSearchWidget.js +++ b/resources/src/mediawiki.widgets/mw.widgets.TitleSearchWidget.js @@ -11,6 +11,7 @@ * * @class * @extends OO.ui.SearchWidget + * @mixins OO.ui.mixin.RequestManager * @mixins mw.widgets.TitleWidget * * @constructor @@ -23,6 +24,7 @@ // Mixin constructors mw.widgets.TitleWidget.call( this, config ); + OO.ui.mixin.RequestManager.call( this, config ); this.query.setValidation( this.isQueryValid.bind( this ) ); @@ -46,6 +48,7 @@ /* Setup */ OO.inheritClass( mw.widgets.TitleSearchWidget, OO.ui.SearchWidget ); + OO.mixinClass( mw.widgets.TitleSearchWidget, OO.ui.mixin.RequestManager ); OO.mixinClass( mw.widgets.TitleSearchWidget, mw.widgets.TitleWidget ); /* Methods */ @@ -72,19 +75,30 @@ mw.widgets.TitleSearchWidget.prototype.onQueryChange = function () { var widget = this; - if ( this.currentRequest ) { - this.currentRequest.abort(); - } - - this.currentRequest = this.getSuggestionsPromise(); - this.currentRequest.done( function ( response ) { + this.getRequestData().done( function ( data ) { // Parent method mw.widgets.TitleSearchWidget.parent.prototype.onQueryChange.call( widget ); - - widget.results.addItems( widget.getOptionsFromData( response.query || {} ) ); - - widget.currentRequest = false; + widget.results.addItems( widget.getOptionsFromData( data ) ); } ); }; + /** + * @inheritdoc OO.ui.mixin.RequestManager + */ + mw.widgets.TitleSearchWidget.prototype.getRequestQuery = function () { + return this.getQueryValue(); + }; + /** + * @inheritdoc OO.ui.mixin.RequestManager + */ + mw.widgets.TitleSearchWidget.prototype.getRequest = function () { + return this.getSuggestionsPromise(); + }; + /** + * @inheritdoc OO.ui.mixin.RequestManager + */ + mw.widgets.TitleSearchWidget.prototype.getRequestCacheDataFromResponse = function ( response ) { + return response.query || {}; + }; + }( jQuery, mediaWiki ) ); -- 2.20.1