Last modified: 2014-07-08 00:08:04 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T50886, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 48886 - ResourceLoader: Remove obsolete closures from files
ResourceLoader: Remove obsolete closures from files
Status: NEW
Product: MediaWiki
Classification: Unclassified
ResourceLoader (Other open bugs)
1.22.0
All All
: Normal enhancement (vote)
: Future release
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2013-05-28 09:33 UTC by Krinkle
Modified: 2014-07-08 00:08 UTC (History)
3 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Krinkle 2013-05-28 09:33:42 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.
Comment 1 Krinkle 2013-05-28 09:35:23 UTC
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
  ...
} );
Comment 2 Krinkle 2014-07-07 23:51:28 UTC
-- 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
} );
Comment 3 Krinkle 2014-07-08 00:08:04 UTC
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).

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links