}
function defineFallbacks() {
- // <https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Set>
+ // <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set>
StringSet = window.Set || ( function () {
/**
* @private
}
/**
- * Converts a module map of the form { foo: [ 'bar', 'baz' ], bar: [ 'baz, 'quux' ] }
- * to a query string of the form foo.bar,baz|bar.baz,quux
+ * Converts a module map of the form `{ foo: [ 'bar', 'baz' ], bar: [ 'baz, 'quux' ] }`
+ * to a query string of the form `foo.bar,baz|bar.baz,quux`.
+ *
+ * See `ResourceLoader::makePackedModulesString()` in PHP, of which this is a port.
+ * On the server, unpacking is done by `ResourceLoaderContext::expandModuleNames()`.
+ *
+ * Note: This is only half of the logic, the other half has to be in #batchRequest(),
+ * because its implementation needs to keep track of potential string size in order
+ * to decide when to split the requests due to url size.
*
* @private
* @param {Object} moduleMap Module map
* Make a network request to load modules from the server.
*
* @private
- * @param {Object} moduleMap Module map, see #buildModulesString
+ * @param {string} moduleStr Module list for load.php `module` query parameter
* @param {Object} currReqBase Object with other parameters (other than 'modules') to use in the request
* @param {string} sourceLoadScript URL of load.php
*/
- function doRequest( moduleMap, currReqBase, sourceLoadScript ) {
+ function doRequest( moduleStr, currReqBase, sourceLoadScript ) {
// Optimisation: Inherit (Object.create), not copy ($.extend)
var query = Object.create( currReqBase );
- query.modules = buildModulesString( moduleMap );
+ query.modules = moduleStr;
query = sortQuery( query );
addScript( sourceLoadScript + '?' + $.param( query ) );
}
// but don't create empty requests
if ( maxQueryLength > 0 && !$.isEmptyObject( moduleMap ) && l + bytesAdded > maxQueryLength ) {
// This url would become too long, create a new one, and start the old one
- doRequest( moduleMap, currReqBase, sourceLoadScript );
+ doRequest( buildModulesString( moduleMap ), currReqBase, sourceLoadScript );
moduleMap = {};
l = currReqBaseLength + 9;
mw.track( 'resourceloader.splitRequest', { maxQueryLength: maxQueryLength } );
}
// If there's anything left in moduleMap, request that too
if ( !$.isEmptyObject( moduleMap ) ) {
- doRequest( moduleMap, currReqBase, sourceLoadScript );
+ doRequest( buildModulesString( moduleMap ), currReqBase, sourceLoadScript );
}
}
}
* OO.compare( [ 1 ], [ 1 ] );
* } );
*
+ * Example of inline dependency obtained via `require()`:
+ *
+ * mw.loader.using( [ 'mediawiki.util' ], function ( require ) {
+ * var util = require( 'mediawiki.util' );
+ * } );
+ *
* Since MediaWiki 1.23 this also returns a promise.
*
* Since MediaWiki 1.28 the promise is resolved with a `require` function.
/**
* Get the exported value of a module.
*
- * Modules may provide this via their local `module.exports`.
+ * This static method is publicly exposed for debugging purposes
+ * only and must not be used in production code. In production code,
+ * please use the dynamically provided `require()` function instead.
*
- * @protected
+ * In case of lazy-loaded modules via mw.loader#using(), the returned
+ * Promise provides the function, see #using() for examples.
+ *
+ * @private
* @since 1.27
* @param {string} moduleName Module name
* @return {Mixed} Exported value