resourceloader: Remove support for `state(name, state)` signature
authorTimo Tijhof <krinklemail@gmail.com>
Mon, 13 Aug 2018 23:55:48 +0000 (00:55 +0100)
committerKrinkle <krinklemail@gmail.com>
Tue, 14 Aug 2018 00:01:42 +0000 (00:01 +0000)
This has no usage in non-test code anywhere in Wikimedia Git,
and was only used in the test suite for mw.loader in core,
and in the test suite for the NavigationTiming extension.

The core usage is as part of this commit. The usage in NavTiming
is updated by I240ced4e65988f9.

Bug: T127328
Depends-On: I240ced4e65988f96c7ece3772378c2c9a335fb9a
Change-Id: Ic17c797e528feaf07a4777709d705615fea353e5

includes/resourceloader/ResourceLoader.php
resources/src/startup/mediawiki.js
tests/qunit/data/load.mock.php
tests/qunit/suites/resources/mediawiki/mediawiki.loader.test.js

index 637bae6..2843ba8 100644 (file)
@@ -1298,8 +1298,8 @@ MESSAGE;
        }
 
        /**
-        * Returns a JS call to mw.loader.state, which sets the state of a
-        * module or modules to a given value. Has two calling conventions:
+        * Returns a JS call to mw.loader.state, which sets the state of one
+        * ore more modules to a given value. Has two calling conventions:
         *
         *    - ResourceLoader::makeLoaderStateScript( $name, $state ):
         *         Set the state of a single module called $name to $state
@@ -1307,24 +1307,19 @@ MESSAGE;
         *    - ResourceLoader::makeLoaderStateScript( [ $name => $state, ... ] ):
         *         Set the state of modules with the given names to the given states
         *
-        * @param string $name
+        * @param array|string $states
         * @param string|null $state
         * @return string JavaScript code
         */
-       public static function makeLoaderStateScript( $name, $state = null ) {
-               if ( is_array( $name ) ) {
-                       return Xml::encodeJsCall(
-                               'mw.loader.state',
-                               [ $name ],
-                               self::inDebugMode()
-                       );
-               } else {
-                       return Xml::encodeJsCall(
-                               'mw.loader.state',
-                               [ $name, $state ],
-                               self::inDebugMode()
-                       );
+       public static function makeLoaderStateScript( $states, $state = null ) {
+               if ( !is_array( $states ) ) {
+                       $states = [ $states => $state ];
                }
+               return Xml::encodeJsCall(
+                       'mw.loader.state',
+                       [ $states ],
+                       self::inDebugMode()
+               );
        }
 
        /**
index 63d23d8..d586fc9 100644 (file)
                                /**
                                 * Change the state of one or more modules.
                                 *
-                                * @param {string|Object} module Module name or object of module name/state pairs
-                                * @param {string} state State name
+                                * @param {Object|string} modules Object of module name/state pairs
                                 */
-                               state: function ( module, state ) {
-                                       var m;
-
-                                       if ( typeof module === 'object' ) {
-                                               for ( m in module ) {
-                                                       mw.loader.state( m, module[ m ] );
+                               state: function ( modules ) {
+                                       var module, state;
+                                       for ( module in modules ) {
+                                               state = modules[ module ];
+                                               if ( !hasOwn.call( registry, module ) ) {
+                                                       mw.loader.register( module );
+                                               }
+                                               registry[ module ].state = state;
+                                               if ( state === 'ready' || state === 'error' || state === 'missing' ) {
+                                                       // Make sure pending modules depending on this one get executed if their
+                                                       // dependencies are now fulfilled!
+                                                       handlePending( module );
                                                }
-                                               return;
-                                       }
-                                       if ( !hasOwn.call( registry, module ) ) {
-                                               mw.loader.register( module );
-                                       }
-                                       registry[ module ].state = state;
-                                       if ( state === 'ready' || state === 'error' || state === 'missing' ) {
-                                               // Make sure pending modules depending on this one get executed if their
-                                               // dependencies are now fulfilled!
-                                               handlePending( module );
                                        }
                                },
 
index 3b710c4..2238fce 100644 (file)
@@ -103,7 +103,7 @@ if ( isset( $_GET['modules'] ) ) {
                                . '} );';
                } else {
                        // Default
-                       $response .= 'mw.loader.state(' . json_encode( $module ) . ', "missing" );' . "\n";
+                       $response .= 'mw.loader.state(' . json_encode( [ $module => 'missing' ] ) . ');' . "\n";
                }
        }
 }
index 05b85be..1a1affa 100644 (file)
                assert.strictEqual( mw.loader.getState( 'test.module7' ), 'registered', 'Expected "registered" state for test.module7' );
                assert.strictEqual( mw.loader.getState( 'test.module8' ), 'loaded', 'Expected "loaded" state for test.module8' );
                assert.strictEqual( mw.loader.getState( 'test.module9' ), 'registered', 'Expected "registered" state for test.module9' );
-               mw.loader.state( 'test.module7', 'missing' );
+               mw.loader.state( { 'test.module7': 'missing' } );
                assert.strictEqual( mw.loader.getState( 'test.module7' ), 'missing', 'Expected "missing" state for test.module7' );
                assert.strictEqual( mw.loader.getState( 'test.module8' ), 'error', 'Expected "error" state for test.module8' );
                assert.strictEqual( mw.loader.getState( 'test.module9' ), 'error', 'Expected "error" state for test.module9' );
                        },
                        function ( e, badmodules ) {
                                assert.ok( true, 'Error handler should be invoked.' );
-                               // As soon as server spits out state('testMissing', 'missing');
+                               // As soon as server sets state of 'testMissing' to 'missing'
                                // it will bubble up and trigger the error callback.
                                // Therefor the badmodules array is not testUsesMissing or testUsesNestedMissing.
                                assert.deepEqual( badmodules, [ 'testMissing' ], 'Bad modules as expected.' );