These are chat archives for systemjs/systemjs

15th
Jan 2015
Joe Pea
@trusktr
Jan 15 2015 00:26
For sure. So continuing that discussion, I don’t see why it wouldn’t be possible to statically analyze the dependencies of a file, disregarding whether or not the deps are imported dynamically in a function, and just have those modules loaded ready in case if the file’s code flow does reach that point.
Basically I don’t get how dynamically loading modules prevents static analysis. Maybe I don’t see the issues since I’m not writing the loaders. xD
@guybedford
Guy Bedford
@guybedford
Jan 15 2015 07:57
@trusktr in NodeJS, dynamic loading and static loading are one function - require(), and this works because require is synchronous in Node, despite Node's philosophy of async.
For ES6, we're dealing with the browser, so the module resolution has to be async by default
static loading and dynamic loading are now two separate things
the one represents the modules that need to be loaded before the module is run
-> this is module syntax
the other represents the modules that I load during runtime
-> this is System.import
both can be traced and reasoned about
but module syntax represents modules that must be loaded and executed before this one
Guy Bedford
@guybedford
Jan 15 2015 09:08
@trusktr the plan is to add a dynamic tracing layer to jspm to detect dynamic System.import('page/newpage') style calls and automate layered bundle creation
Austin
@amcdnl
Jan 15 2015 17:34
@justinbmeyer - after some tweaking i got it to work :) ... i'll share my solution with the group when i get it fully working
Joe Pea
@trusktr
Jan 15 2015 20:40

@guybedford It all makes sense. So if I have

// foo.js
import blah from 'blah'
var foo = function() {
  import bar from 'bar' // not lazy loaded
  console.log(bar)
}
export foo

would it be possible to load both bar and blah modules they don’t depend on each other) asynchrously before executing the foo.js file, then just giving the foo function scope the bar variable when it needs it? It wouldn’t be lazy loading, but it would still work.

Random async idea:

// foo.js
import blah from 'blah'
var foo = function() {
  var abc = 'abc';
  import bar from 'bar' then { // lazy loaded right at this point in time.

    // still in the function's scope, returns later,
    // making foo "synchronous" on the outside.
    return bar + abc;
  }
}
export foo

or

// foo.js
import blah from 'blah'
var foo = function(callback) {
  import bar from 'bar' then
    callback(bar)
  return "yoohoo"; // doesn’t return later.
}
export foo
Kris Williams
@kriswill
Jan 15 2015 20:48
in a web browser wouldn’t ES6 import be automatically async?
that is if the browser had native support
I think the Promises way will be like:
Promise.all(['module1', 'module2', 'module3'].map(x => System.import(x)))
    .then(function ([module1, module2, module3]) {
      // loaded
    })
Joe Pea
@trusktr
Jan 15 2015 21:22
Yeah, I wonder too. Will browsers load modules when they see the import statement? Or will that be the job of the loader, which basically converts your code on the fly like SystemJS does?
Kris Williams
@kriswill
Jan 15 2015 21:23
I think they will essentially translate it to System.import()
and import will return the promises function chain