Page MenuHomePhabricator

ResourceLoader: Modules should be able to specify dependencies evaluated at run-time
Closed, ResolvedPublic

Description

Sometimes modules have dependencies that can't be determined until runtime; most obviously, code that requires shims for browser functionality that may be missing on a few clients.

It would be great if instead of static dependencies, modules could specify dependencies that are evaluated at run-time and only loaded if needed.


Version: 1.24rc
Severity: enhancement
See Also:
https://bugzilla.wikimedia.org/show_bug.cgi?id=56341

Details

Reference
bz66390

Event Timeline

bzimport raised the priority of this task from to High.
bzimport set Reference to bz66390.

Change 135085 had a related patch set uploaded by Jforrester:
[WIP] resourceloader: Implement "skip function" feature

https://gerrit.wikimedia.org/r/135085

Per discussion between Roan and me we're taking this use case as a story rather than a specific call to implementation.

We won't be adding a feature to conditionally declare something as a dependency. So the following will not be the how it is used:

visualeditor.dependencies = [es5]
->
visualeditor.dependencies = function (deps) {

if ( browser doesn't support es5 ) {
  deps.push( es5);
}

};

Instead we're going to take it the other way around and have the condition be on the target module (e.g. es5.js instead of visualeditor).

visualeditor.dependencies = [es5]
es5.skip = function () {

return browser supports es5;

};

This way will result in much less duplication, and feels more semantically correct because it doesn't make sense for an application to have a dependency that can change. Modules are supposed to be a canonical representation of an interface, not a specific implementation, skin, language or file. Either the module to provide it or it doesn't. Instead visualeditor (or indeed, oojs) would declare it needs the thing that es5-shim.js provides. And es5-shim can decide to forego fetching of any actual files if it detects the environment has it already (either by native or another polyfill).

This will make the experience for developers much easier (no need to duplicate if -conditions for es5 all over the place) and practically removes any possibility of abusing this feature for implementing any bad ideas.

Change 135085 merged by jenkins-bot:
resourceloader: Implement "skip function" feature

https://gerrit.wikimedia.org/r/135085