jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/343779 )

Change subject: Tour: Fix initialize() race condition
......................................................................


Tour: Fix initialize() race condition

Follows-up I4e9b366613bc.

Change-Id: If56e392cbc2c5faaa550a85110c74001ccd20825
---
M modules/ext.guidedTour.lib/ext.guidedTour.lib.Tour.js
M tests/qunit/ext.guidedTour.lib.tests.js
2 files changed, 17 insertions(+), 21 deletions(-)

Approvals:
  jenkins-bot: Verified
  Jforrester: Looks good to me, approved



diff --git a/modules/ext.guidedTour.lib/ext.guidedTour.lib.Tour.js 
b/modules/ext.guidedTour.lib/ext.guidedTour.lib.Tour.js
index a11b6fa..a3d1ed8 100644
--- a/modules/ext.guidedTour.lib/ext.guidedTour.lib.Tour.js
+++ b/modules/ext.guidedTour.lib/ext.guidedTour.lib.Tour.js
@@ -134,12 +134,12 @@
                this.isExtensionDefined = ( mw.loader.getState( moduleName ) 
!== null );
 
                /**
-                * Whether this tour has been initialized (guiders have been 
created)
+                * Promise tracking when this tour is initialized (guiders have 
been created)
                 *
-                * @property {boolean}
+                * @property {null|jQuery.Deferred}
                 * @private
                 */
-               this.isInitialized = false;
+               this.initialized = null;
        }
 
        // TODO: Change this to use before/after (T142267)
@@ -191,24 +191,20 @@
         * @return {jQuery.Promise} Promise that waits on all steps to 
initialize (or one to fail)
         */
        Tour.prototype.initialize = function () {
-               var stepName, promises = [], tour = this,
+               var stepName, promises = [],
                        $body = $( document.body ),
                        interfaceDirection = $( 'html' ).attr( 'dir' ),
                        siteDirection = $body.hasClass( 'sitedir-ltr' ) ? 'ltr' 
: 'rtl';
 
-               if ( this.isInitialized ) {
-                       return $.Deferred().resolve();
+               if ( !this.initialized ) {
+                       this.flipRTL = this.getShouldFlipHorizontally( 
interfaceDirection, siteDirection );
+                       for ( stepName in this.steps ) {
+                               promises.push( this.steps[ stepName 
].initialize() );
+                       }
+                       this.initialized = $.when.apply( $, promises );
                }
 
-               this.flipRTL = this.getShouldFlipHorizontally( 
interfaceDirection, siteDirection );
-
-               for ( stepName in this.steps ) {
-                       promises.push( this.steps[stepName].initialize() );
-               }
-
-               return $.when.apply( $, promises ).then( function () {
-                       tour.isInitialized = true;
-               } );
+               return this.initialized;
        };
 
        /**
diff --git a/tests/qunit/ext.guidedTour.lib.tests.js 
b/tests/qunit/ext.guidedTour.lib.tests.js
index ca65cf8..33c5e77 100644
--- a/tests/qunit/ext.guidedTour.lib.tests.js
+++ b/tests/qunit/ext.guidedTour.lib.tests.js
@@ -1462,13 +1462,13 @@
                var checkTransitionSpy = this.spy( firstStep, 'checkTransition' 
),
                        actualTransitionEvent, expectedTransitionEvent;
 
+               validTour.showStep( firstStep );
+
+               expectedTransitionEvent = new gt.TransitionEvent();
+               expectedTransitionEvent.type = gt.TransitionEvent.BUILTIN;
+               expectedTransitionEvent.subtype = 
gt.TransitionEvent.TRANSITION_BEFORE_SHOW;
+
                return validTour.initialize().then( function () {
-                       validTour.showStep( firstStep );
-
-                       expectedTransitionEvent = new gt.TransitionEvent();
-                       expectedTransitionEvent.type = 
gt.TransitionEvent.BUILTIN;
-                       expectedTransitionEvent.subtype = 
gt.TransitionEvent.TRANSITION_BEFORE_SHOW;
-
                        actualTransitionEvent = 
checkTransitionSpy.lastCall.args[ 0 ];
 
                        assert.deepEqual(

-- 
To view, visit https://gerrit.wikimedia.org/r/343779
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: If56e392cbc2c5faaa550a85110c74001ccd20825
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/GuidedTour
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: Mattflaschen <[email protected]>
Gerrit-Reviewer: Phuedx <[email protected]>
Gerrit-Reviewer: Swalling <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to