Last modified: 2014-11-19 01:57:31 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 T50885, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 48885 - VisualEditor: Load visualeditor modules in a closure mapping $/mw/ve to their globals
VisualEditor: Load visualeditor modules in a closure mapping $/mw/ve to their...
Status: ASSIGNED
Product: VisualEditor
Classification: Unclassified
Technical Debt (Other open bugs)
unspecified
All All
: High enhancement
: VE-deploy-nextup
Assigned To: Krinkle
:
Depends on:
Blocks: 67642
  Show dependency treegraph
 
Reported: 2013-05-28 09:25 UTC by Trevor Parscal
Modified: 2014-11-19 01:57 UTC (History)
4 users (show)

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


Attachments

Description Trevor Parscal 2013-05-28 09:25:04 UTC
This may introduce a really large number of scopes and have undesirable performance effects, but we need to come up with a solution nonetheless.
Comment 1 Krinkle 2013-05-28 09:44:48 UTC
For the record, inside ResourceLoader context $ is a local variable provided by the ResourceLoader built-in closure.

See also bug 48886.
Comment 2 Krinkle 2014-07-07 23:51:15 UTC
I suggest for standalone we introduce an module-intro/outro that is used to wrap around individual modules (not per file).

So e.g. dist/ve.core.js would be:

-- intro
( function ( ve, $ ) {
 -- include ve.js
 -- include ve.A.js
 -- include ve.B.js
 -- include ve.C.js
-- outro
}( VisualEditor, jQuery ) );

And in MediaWiki the same would effectively happen but on-demand by ResourceLoader (since we don't want to use a build system for MW, but instead work on the raw source files directly and have them build dynamically).

See bug 48886 for details, but the end result would be:

-- 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:17:14 UTC
Rephrasing bug.

Problems:


* We're repeatedly referencing $/mw from global scope instead of securing the reference. This is worse for performance and for proper functioning (e.g. jQuery might be redefined at a later time causing version mismatches, this is why ResourceLoader maps $) 

* We're using $ and mw directly instead of mapping jQuery and mediaWiki.

* In standalone, our code executes in the global scope. This is bad.

Solution:

* For standalone, build the dist/ files with a closure mapping, securing and caching '$' from 'jQuery'. And for VE modules other than ve.base, it would also map 've' to 'VisualEditor' (bug 67642)

* In MediaWiki, ResourceLoader already provides a closure which we'd extend to also map 've' to 'VisualEditor'.

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


Navigation
Links