Billy Moon Billy Moon - 1 year ago 99
Javascript Question

System JS load multiple dependencies in one call

Looking at the docs for systemjs I can not find an example of loading multiple dependencies at the same time. I would expect an api something like...

System.import(['jquery.js','underscore.js']).then(function($, _) {
// ready to go with both jQuery and Underscore...

I would expect it to use promises to load all dependencies in parallel, and execute the callback once all are complete. Is this possible? If not, is there a reason why this functionality is not implemented?

Answer Source

This is possible with Promise.all:

]).then(function(modules) {
    var jquery = modules[0];
    var underscore = modules[1];

But it is ugly as you can see. There is talk of considering allowing an array like your example at the spec level, but it would need to be in the module spec since this is a spec loader.

The better alternative really is to only have one entry point for an application, app.js and then have that load dependencies.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download