resourceloader: Remove remnants of "dependencies as a function"
authorTimo Tijhof <krinklemail@gmail.com>
Mon, 23 Apr 2018 18:47:59 +0000 (19:47 +0100)
committerCatrope <roan@wikimedia.org>
Thu, 3 May 2018 22:19:20 +0000 (22:19 +0000)
This hasn't been used in a while, at least two years from what
I could find. It also doesn't have tests, and numerous paths
that possibly should handle it, don't.

This was originally implemented for TMH as a way to dynamically
change what it loads based on the browser environment.

However, this has been addressed by two other aspects already:

* mw.loader.using() - During development of ResourceLoader, this
  method was unstable for a short while. During that pre-release
  time, dynamic dependencies was added as workaround for TMH.
  It being stable addresses TMH's use case of loading *different*
  modules (with callback) based on environment factors.
  This allows complete mutation of the array passed: remove,
  replace, and add operations. This can be used to completely
  change was a module does based on browser environment,
  e.g. load a decoder for X instead of Y, but places the logic
  in the startup module, which is inefficient.
  TMH has switched long ago to using using() instead.

* 'skipFunction' - Introduced in more recent years, this was
  added to more efficiently address the 'remove' use case.
  E.g. where the 'needs' are consistent between browsers, but
  a subset of the needs may be available natively without
  needing a polyfil. The skipFunction allows once to mark
  a module as "ready" without actually loading anything.
  This has been used for efficient and conditional loading of
  DOM2, JSON and ES5 polyfills. (All of which have been removed
  since, but that's a separate story.)

Bug: T192623
Change-Id: Ia97df72a0c3f0fc0dc917fce0a94213b23db4daa

resources/src/mediawiki/mediawiki.js

index 3fe276b..6a2478c 100644 (file)
                         *         'moduleName': {
                         *             // From mw.loader.register()
                         *             'version': '########' (hash)
-                        *             'dependencies': ['required.foo', 'bar.also', ...], (or) function () {}
+                        *             'dependencies': ['required.foo', 'bar.also', ...]
                         *             'group': 'somegroup', (or) null
                         *             'source': 'local', (or) 'anotherwiki'
                         *             'skip': 'return !!window.Example', (or) null
                                        }
                                }
 
-                               // Resolves dynamic loader function and replaces it with its own results
-                               if ( typeof registry[ module ].dependencies === 'function' ) {
-                                       registry[ module ].dependencies = registry[ module ].dependencies();
-                                       // Ensures the module's dependencies are always in an array
-                                       if ( typeof registry[ module ].dependencies !== 'object' ) {
-                                               registry[ module ].dependencies = [ registry[ module ].dependencies ];
-                                       }
-                               }
                                if ( resolved.indexOf( module ) !== -1 ) {
                                        // Module already resolved; nothing to do
                                        return;
                                 *  a list of arguments compatible with this method
                                 * @param {string|number} version Module version hash (falls backs to empty string)
                                 *  Can also be a number (timestamp) for compatibility with MediaWiki 1.25 and earlier.
-                                * @param {string|Array|Function} dependencies One string or array of strings of module
-                                *  names on which this module depends, or a function that returns that array.
+                                * @param {string|Array} dependencies One string or array of strings of module
+                                *  names on which this module depends.
                                 * @param {string} [group=null] Group which the module is in
                                 * @param {string} [source='local'] Name of the source
                                 * @param {string} [skip=null] Script body of the skip function
                                        if ( typeof dependencies === 'string' ) {
                                                // A single module name
                                                deps = [ dependencies ];
-                                       } else if ( typeof dependencies === 'object' || typeof dependencies === 'function' ) {
-                                               // Array of module names or a function that returns an array
+                                       } else if ( typeof dependencies === 'object' ) {
+                                               // Array of module names
                                                deps = dependencies;
                                        }
                                        // List the module as registered