Last modified: 2014-07-08 00:08:04 UTC
Situation: * ResourceLoader wraps modules in closures * MediaWiki developers put a closure in each file * As a result loading 1 module with 2 files will have 3 closures mw.loader.implement( 'foo', function ( $ ) { --- foo.a.js ( function ( $, mw ) { ... }( jQuery, mediaWiki ) ) --- foo.b.js ( function ( $, mw ) { ... }( jQuery, mediaWiki ) ) } ); mw.loader# script( jQuery ); It has been suggested we add "mw" to ResourceLoader's closure and get rid of the per-file closure. The downside of doing that would be that they are less safe to use "standalone". e.g. a jquery plugin would be using $ directly, which, outside MediaWiki ResourceLoader context is bad. There is also the pending refactoring of ResourceLoader debug mode to not be completely different and near useless by executing in the global scope.
Also: modules['bar'] = { scripts: ['bar.a.js', 'bar.b.js'], globals: { ba: Bar } }; mw.loader.implement( 'foo', function ( $, mw, ba ) { --- bar.a.js ... --- bar.b.js ... } );
-- startup: register( .., [ 'ext.visualEditor', 1234, ...., ['VisualEditor'] ); -- mw.loader: script( $, global[propKeys..].. ); -- load.php response when loading visualeditor: mw.loader.implement( 'ext.visualEditor.core', function ( $, ve ) { -- include ve.js -- include ve.A.js -- include ve.B.js -- include ve.C.js } );
Note that this bug isn't blocked on implementing global variable mappings. This bug basically says: * Closures added by ResourceLoader are not merely a by-product of the deferred loading. They are part of the eco system and to be relied on. * Drop the tradition that each .js file should be loadable raw and standalone and instead embrace the dynamic build system. The main thing blocking this is debug mode. We need to refactor debug mode to not load raw files (bug 62605). Instead it should merely keep them deminified. Ideally with support for source maps (bug 45514).