On 14 February 2014 14:13, C. Scott Ananian <ecmascr...@cscott.net> wrote:
> Can someone point me to the spec for `System.import`? > It's in the ES6 specification draft under Loader.prototype.import - https://people.mozilla.org/~jorendorff/es6-draft.html#sec-loader.prototype.import . > > https://github.com/jorendorff/js-loaders/blob/master/browser-loader.js > doesn't seem to include it. > > It seems to me that it would be worthwhile to ensure that > `System.import` had good semantics. It would allow a nice migration > path for existing AMD and node-style modules. For example: > > ```js > // AMD-style define! > // (Promise.map and Promise.spread would be nice here; see > // https://github.com/cscott/prfun) > function define(deps, f) { > return Promise.all(deps.map(d => System.import(d))) > .then( (...args) => f(...args) ) > .then( registerModule ) > } > ``` > This is not the recommended way to register a module - rather this is what Dynamic Instantiation is designed to handle for you, so there is no need to work out how to link the dependencies manually. See https://gist.github.com/dherman/7568080 or the outdated (using old syntax, but the principles remain) essay https://gist.github.com/wycats/51c96e3adcdb3a68cbc3 for more info. > > and > > ```js > // Node-style require needs more magic. > Promise.async(function*() { > /* start module text */ > var fs = yield System.import('fs'); > // etc. > /* end module text */ > return module.exports; > }).then( registerModule ); > ``` > Again, this is solved by dynamic instantiation. > > But that implies that `System.import` has well defined cycle-breaking, > extensibility, etc. Could it? > --scott > > ps. https://gist.github.com/wycats/51c96e3adcdb3a68cbc3/#comment-1006744 > > -- > ( http://cscott.net/ ) > _______________________________________________ > es-discuss mailing list > es-discuss@mozilla.org > https://mail.mozilla.org/listinfo/es-discuss >
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss