Jdlrobson has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/312082

Change subject: Use module registry for defining ext.popups.experiment
......................................................................

Use module registry for defining ext.popups.experiment

Since it's a single file module, this can safely and effortlessly
be used rather than adding itself to the global popups object

Change-Id: I2a0f80d989e28fe8b361abd1a7b01d5fe735cec5
---
M resources/ext.popups.core.js
M resources/ext.popups.experiment.js
M resources/ext.popups.init.js
M tests/qunit/ext.popups.experiment.test.js
4 files changed, 14 insertions(+), 14 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Popups 
refs/changes/82/312082/1

diff --git a/resources/ext.popups.core.js b/resources/ext.popups.core.js
index 17157d2..af0d306 100644
--- a/resources/ext.popups.core.js
+++ b/resources/ext.popups.core.js
@@ -1,12 +1,8 @@
 ( function ( $, mw ) {
        'use strict';
        var previewCountStorageKey = 'ext.popups.core.previewCount',
+               experiment = require( 'ext.popups.experiment' ),
                popupsEnabledStorageKey = 'mwe-popups-enabled';
-
-       /**
-        * @class mw.popups
-        * @singleton
-        */
 
        /**
         * The API object used for all this extension's requests
@@ -236,7 +232,7 @@
                if ( !mw.config.get( 'wgPopupsExperiment', false ) ) {
                        return mw.storage.get( popupsEnabledStorageKey ) !== 
'0';
                } else {
-                       return mw.popups.experiment.isUserInCondition();
+                       return experiments.isUserInCondition();
                }
        };
 
diff --git a/resources/ext.popups.experiment.js 
b/resources/ext.popups.experiment.js
index 48c3be7..e2c1571 100644
--- a/resources/ext.popups.experiment.js
+++ b/resources/ext.popups.experiment.js
@@ -59,7 +59,7 @@
         *
         * @return {boolean}
         */
-       mw.popups.experiment.isUserInCondition = function isUserInCondition() {
+       function isUserInCondition() {
                var config = mw.config.get( 'wgPopupsExperimentConfig' );
 
                // The first two tests deal with whether the user has 
/explicitly/ enable or disabled via its
@@ -87,4 +87,8 @@
                }
        };
 
+       module.exports = {
+               isUserInCondition: isUserInCondition
+       };
+
 }( mediaWiki ) );
diff --git a/resources/ext.popups.init.js b/resources/ext.popups.init.js
index ccf19e8..857bdef 100644
--- a/resources/ext.popups.init.js
+++ b/resources/ext.popups.init.js
@@ -4,6 +4,5 @@
        // Initialize singletons/namespaces.
        mw.popups = {};
        mw.popups.render = {};
-       mw.popups.experiment = {};
 
 }( mediaWiki ) );
diff --git a/tests/qunit/ext.popups.experiment.test.js 
b/tests/qunit/ext.popups.experiment.test.js
index 2e52b81..b9ac465 100644
--- a/tests/qunit/ext.popups.experiment.test.js
+++ b/tests/qunit/ext.popups.experiment.test.js
@@ -1,4 +1,5 @@
 ( function ( mw ) {
+       var experiment = require( 'ext.popups.experiment' );
 
        QUnit.module( 'ext.popups.experiment', QUnit.newMwEnvironment( {
                config: {
@@ -31,7 +32,7 @@
                mw.config.set( 'wgPopupsExperimentIsBetaFeatureEnabled', true );
 
                assert.strictEqual(
-                       mw.popups.experiment.isUserInCondition(),
+                       experiment.isUserInCondition(),
                        true,
                        'If the user has the beta feature enabled, then they 
aren\'t in the condition.'
                );
@@ -43,7 +44,7 @@
                        result,
                        firstCallArgs;
 
-               result = mw.popups.experiment.isUserInCondition();
+               result = experiment.isUserInCondition();
 
                firstCallArgs = getBucketSpy.firstCall.args;
 
@@ -66,7 +67,7 @@
 
                this.sandbox.stub( mw.user, 'generateRandomSessionId' 
).returns( token );
 
-               mw.popups.experiment.isUserInCondition();
+               experiment.isUserInCondition();
 
                assert.deepEqual(
                        setSpy.firstCall.args[ 1 ],
@@ -79,7 +80,7 @@
                mw.config.set( 'wgPopupsExperimentConfig', null );
 
                assert.strictEqual(
-                       mw.popups.experiment.isUserInCondition(),
+                       experiment.isUserInCondition(),
                        false,
                        'If the experiment isn\'t configured, then the user 
isn\'t in the condition.'
                );
@@ -89,7 +90,7 @@
                mw.storage.set( 'mwe-popups-enabled', '1' );
 
                assert.strictEqual(
-                       mw.popups.experiment.isUserInCondition(),
+                       experiment.isUserInCondition(),
                        true,
                        'If the experiment has enabled the feature, then the 
user is in the condition.'
                );
@@ -102,7 +103,7 @@
                mw.storage.set( 'mwe-popups-enabled', '0' );
 
                assert.strictEqual(
-                       mw.popups.experiment.isUserInCondition(),
+                       experiment.isUserInCondition(),
                        false,
                        'If the experiment has enabled the feature, then the 
user is in the condition.'
                );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2a0f80d989e28fe8b361abd1a7b01d5fe735cec5
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Popups
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <jrob...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to