Last modified: 2012-08-09 20:02:01 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 T40782, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 38782 - Allow mw.loader.using adding dependency without loading the module
Allow mw.loader.using adding dependency without loading the module
Status: RESOLVED WONTFIX
Product: MediaWiki
Classification: Unclassified
JavaScript (Other open bugs)
unspecified
All All
: Low enhancement (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-07-28 21:16 UTC by Umherirrender
Modified: 2012-08-09 20:02 UTC (History)
3 users (show)

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


Attachments

Description Umherirrender 2012-07-28 21:16:37 UTC
When manipulate the toolbar with user or site javascript you have to wait until 'mediawiki.action.edit' is "ready", but the code

mw.loader.using( [ 'mediawiki.action.edit' ], function() {
...
});

will load 'mediawiki.action.edit' on each page. Adding a check for wgAction !== edit and submit is a solution, but for other modules you have to know, where it is running and adding that check, that is bad, when the condition is changed.

Having a method inside the loader, which allow executing a function after all dependency are ready without requesting the modules, can help here. When the page is ready and the dependency is not loaded, than the loader ignore this function.

For example:

mw.loader.usingIfExist( [ 'mediawiki.action.edit' ], function() {
...
});

will only executing the function when 'mediawiki.action.edit' is loaded on the page and will not requesting the module itself. When the module is not loaded, the function is ignored.
Comment 1 Krinkle 2012-07-31 05:52:34 UTC
Modules are always registered, whether they are going to be loaded or not. The reason is because it is not known in advance what will and will not be loaded.

e.g. an inline "mw.loader.load()" should always work. So "if exist" is not possible.

Alternatively "if loaded" could be an option (e.g. mw.loader.callWhenLoaded( ['mediawiki.action.edit'], fn );, which will call the function when that module is loaded, but it would not initiate a load request.

Though it could be useful, I'd argue the only use case it serves are work-arounds that can and should be solved other wise. If there are non-hacky use cases for it, I'd be happy to consider it though.


In the case of the edit toolbar the proper solution imho is to use a hook.
Comment 2 Umherirrender 2012-08-09 20:02:01 UTC
Yes, hooks are better.

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


Navigation
Links