dynamic synchronous import
no.
no. On Fri, Sep 26, 2014 at 8:12 AM, Konstantin Ikonnikov <ikokostya at gmail.com> wrote: > Can I import module dynamically, but synchronously? Example for common js > > ```js > var moduleName = 'foo'; > var foo = require(moduleName); > ``` > > In es6 draft I found that ModuleSpecifier must be a StringLiteral > http://people.mozilla.org/~jorendorff/es6-draft.html#sec-imports > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140926/100c8eff/attachment-0001.html>
And the reason you cannot import a module synchronously is that it would freeze the entire browser until the http request completes, which could be several seconds on a slow internet connection.
If you want to import something dynamically you can do it using the API (to be finalized, I believe):
var moduleName = 'foo';
Loader.import(moduleName).then(function(foo){
//use foo here
});
And the reason you cannot import a module synchronously is that it would freeze the entire browser until the http request completes, which could be several seconds on a slow internet connection. If you want to import something dynamically you can do it using the API (to be finalized, I believe): ```js var moduleName = 'foo'; Loader.import(moduleName).then(function(foo){ //use foo here }); ``` Marius Gundersen On Fri, Sep 26, 2014 at 5:29 PM, John Barton <johnjbarton at google.com> wrote: > no. > > On Fri, Sep 26, 2014 at 8:12 AM, Konstantin Ikonnikov <ikokostya at gmail.com > > wrote: > >> Can I import module dynamically, but synchronously? Example for common js >> >> ```js >> var moduleName = 'foo'; >> var foo = require(moduleName); >> ``` >> >> In es6 draft I found that ModuleSpecifier must be a StringLiteral >> http://people.mozilla.org/~jorendorff/es6-draft.html#sec-imports >> >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> >> > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140926/9dd857e6/attachment.html>
Konstantin Ikonnikov wrote:
Can I import module dynamically, but synchronously? Example for common js
var moduleName = 'foo'; var foo = require(moduleName);
You can't do that in the browser, as followups point out. Do you use browserify or similar to make this seem to work? If so, that's not dynamic-synch.
Konstantin Ikonnikov wrote: > Can I import module dynamically, but synchronously? Example for common js > > ```js > var moduleName = 'foo'; > var foo = require(moduleName); > ``` You can't do that in the browser, as followups point out. Do you use browserify or similar to make this seem to work? If so, that's not dynamic-synch. /be
I don't want load module using http request. In my case module already defined and I want import it later when I get its name:
var moduleName = getModuleName();
import { foo } from moduleName;
// use foo
I don't want load module using http request. In my case module already defined and I want import it later when I get its name: ```js var moduleName = getModuleName(); import { foo } from moduleName; // use foo ``` 2014-09-26 20:00 GMT+04:00 Marius Gundersen <gundersen at gmail.com>: > And the reason you cannot import a module synchronously is that it would > freeze the entire browser until the http request completes, which could be > several seconds on a slow internet connection. > > If you want to import something dynamically you can do it using the API > (to be finalized, I believe): > > ```js > var moduleName = 'foo'; > Loader.import(moduleName).then(function(foo){ > //use foo here > }); > ``` > > Marius Gundersen > > On Fri, Sep 26, 2014 at 5:29 PM, John Barton <johnjbarton at google.com> > wrote: > >> no. >> >> On Fri, Sep 26, 2014 at 8:12 AM, Konstantin Ikonnikov < >> ikokostya at gmail.com> wrote: >> >>> Can I import module dynamically, but synchronously? Example for common >>> js >>> >>> ```js >>> var moduleName = 'foo'; >>> var foo = require(moduleName); >>> ``` >>> >>> In es6 draft I found that ModuleSpecifier must be a StringLiteral >>> http://people.mozilla.org/~jorendorff/es6-draft.html#sec-imports >>> >>> _______________________________________________ >>> es-discuss mailing list >>> es-discuss at mozilla.org >>> https://mail.mozilla.org/listinfo/es-discuss >>> >>> >> >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140926/858c0f44/attachment.html>
var moduleName = 'foo';
var foo = require(moduleName);
would not work in browserify either
```js var moduleName = 'foo'; var foo = require(moduleName); ``` would not work in browserify either On Fri, Sep 26, 2014 at 12:40 PM, Konstantin Ikonnikov <ikokostya at gmail.com> wrote: > I don't want load module using http request. In my case module already > defined and I want import it later when I get its name: > > ```js > var moduleName = getModuleName(); > import { foo } from moduleName; > > // use foo > ``` > > > > 2014-09-26 20:00 GMT+04:00 Marius Gundersen <gundersen at gmail.com>: > >> And the reason you cannot import a module synchronously is that it would >> freeze the entire browser until the http request completes, which could be >> several seconds on a slow internet connection. >> >> If you want to import something dynamically you can do it using the API >> (to be finalized, I believe): >> >> ```js >> var moduleName = 'foo'; >> Loader.import(moduleName).then(function(foo){ >> //use foo here >> }); >> ``` >> >> Marius Gundersen >> >> On Fri, Sep 26, 2014 at 5:29 PM, John Barton <johnjbarton at google.com> >> wrote: >> >>> no. >>> >>> On Fri, Sep 26, 2014 at 8:12 AM, Konstantin Ikonnikov < >>> ikokostya at gmail.com> wrote: >>> >>>> Can I import module dynamically, but synchronously? Example for common >>>> js >>>> >>>> ```js >>>> var moduleName = 'foo'; >>>> var foo = require(moduleName); >>>> ``` >>>> >>>> In es6 draft I found that ModuleSpecifier must be a StringLiteral >>>> http://people.mozilla.org/~jorendorff/es6-draft.html#sec-imports >>>> >>>> _______________________________________________ >>>> es-discuss mailing list >>>> es-discuss at mozilla.org >>>> https://mail.mozilla.org/listinfo/es-discuss >>>> >>>> >>> >>> _______________________________________________ >>> es-discuss mailing list >>> es-discuss at mozilla.org >>> https://mail.mozilla.org/listinfo/es-discuss >>> >>> >> > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > -- -Calvin W. Metcalf -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140926/beb07156/attachment.html>
It does work in browserify, but you need to be sure to include it in a list
of requires if it is not imported by the current list of files statically
(ala browserify -e main.js -r foo
).
> ```js > var moduleName = 'foo'; > var foo = require(moduleName); > ``` > > would not work in browserify either It does work in browserify, but you need to be sure to include it in a list of requires if it is not imported by the current list of files statically (ala `browserify -e main.js -r foo`). On Fri, Sep 26, 2014 at 12:21 PM, Calvin Metcalf <calvin.metcalf at gmail.com> wrote: > > ```js > var moduleName = 'foo'; > var foo = require(moduleName); > ``` > > would not work in browserify either > > On Fri, Sep 26, 2014 at 12:40 PM, Konstantin Ikonnikov < > ikokostya at gmail.com> wrote: > >> I don't want load module using http request. In my case module already >> defined and I want import it later when I get its name: >> >> ```js >> var moduleName = getModuleName(); >> import { foo } from moduleName; >> >> // use foo >> ``` >> >> >> >> 2014-09-26 20:00 GMT+04:00 Marius Gundersen <gundersen at gmail.com>: >> >>> And the reason you cannot import a module synchronously is that it would >>> freeze the entire browser until the http request completes, which could be >>> several seconds on a slow internet connection. >>> >>> If you want to import something dynamically you can do it using the API >>> (to be finalized, I believe): >>> >>> ```js >>> var moduleName = 'foo'; >>> Loader.import(moduleName).then(function(foo){ >>> //use foo here >>> }); >>> ``` >>> >>> Marius Gundersen >>> >>> On Fri, Sep 26, 2014 at 5:29 PM, John Barton <johnjbarton at google.com> >>> wrote: >>> >>>> no. >>>> >>>> On Fri, Sep 26, 2014 at 8:12 AM, Konstantin Ikonnikov < >>>> ikokostya at gmail.com> wrote: >>>> >>>>> Can I import module dynamically, but synchronously? Example for >>>>> common js >>>>> >>>>> ```js >>>>> var moduleName = 'foo'; >>>>> var foo = require(moduleName); >>>>> ``` >>>>> >>>>> In es6 draft I found that ModuleSpecifier must be a StringLiteral >>>>> http://people.mozilla.org/~jorendorff/es6-draft.html#sec-imports >>>>> >>>>> _______________________________________________ >>>>> es-discuss mailing list >>>>> es-discuss at mozilla.org >>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>> >>>>> >>>> >>>> _______________________________________________ >>>> es-discuss mailing list >>>> es-discuss at mozilla.org >>>> https://mail.mozilla.org/listinfo/es-discuss >>>> >>>> >>> >> >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> >> > > > -- > -Calvin W. Metcalf > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140926/1b1b1502/attachment.html>
true and by that same token it is possible to use the loader api to get similar results out of ES6 modules (calvinmetcalf/es6-translate)
true and by that same token it is possible to use the loader api to get similar results out of ES6 modules ( https://github.com/calvinmetcalf/es6-translate) On Fri, Sep 26, 2014 at 3:46 PM, Bradley Meck <bradley.meck at gmail.com> wrote: > > ```js > > var moduleName = 'foo'; > > var foo = require(moduleName); > > ``` > > > > would not work in browserify either > > It does work in browserify, but you need to be sure to include it in a > list of requires if it is not imported by the current list of files > statically (ala `browserify -e main.js -r foo`). > > On Fri, Sep 26, 2014 at 12:21 PM, Calvin Metcalf <calvin.metcalf at gmail.com > > wrote: > >> >> ```js >> var moduleName = 'foo'; >> var foo = require(moduleName); >> ``` >> >> would not work in browserify either >> >> On Fri, Sep 26, 2014 at 12:40 PM, Konstantin Ikonnikov < >> ikokostya at gmail.com> wrote: >> >>> I don't want load module using http request. In my case module already >>> defined and I want import it later when I get its name: >>> >>> ```js >>> var moduleName = getModuleName(); >>> import { foo } from moduleName; >>> >>> // use foo >>> ``` >>> >>> >>> >>> 2014-09-26 20:00 GMT+04:00 Marius Gundersen <gundersen at gmail.com>: >>> >>>> And the reason you cannot import a module synchronously is that it >>>> would freeze the entire browser until the http request completes, which >>>> could be several seconds on a slow internet connection. >>>> >>>> If you want to import something dynamically you can do it using the API >>>> (to be finalized, I believe): >>>> >>>> ```js >>>> var moduleName = 'foo'; >>>> Loader.import(moduleName).then(function(foo){ >>>> //use foo here >>>> }); >>>> ``` >>>> >>>> Marius Gundersen >>>> >>>> On Fri, Sep 26, 2014 at 5:29 PM, John Barton <johnjbarton at google.com> >>>> wrote: >>>> >>>>> no. >>>>> >>>>> On Fri, Sep 26, 2014 at 8:12 AM, Konstantin Ikonnikov < >>>>> ikokostya at gmail.com> wrote: >>>>> >>>>>> Can I import module dynamically, but synchronously? Example for >>>>>> common js >>>>>> >>>>>> ```js >>>>>> var moduleName = 'foo'; >>>>>> var foo = require(moduleName); >>>>>> ``` >>>>>> >>>>>> In es6 draft I found that ModuleSpecifier must be a StringLiteral >>>>>> http://people.mozilla.org/~jorendorff/es6-draft.html#sec-imports >>>>>> >>>>>> _______________________________________________ >>>>>> es-discuss mailing list >>>>>> es-discuss at mozilla.org >>>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>>> >>>>>> >>>>> >>>>> _______________________________________________ >>>>> es-discuss mailing list >>>>> es-discuss at mozilla.org >>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>> >>>>> >>>> >>> >>> _______________________________________________ >>> es-discuss mailing list >>> es-discuss at mozilla.org >>> https://mail.mozilla.org/listinfo/es-discuss >>> >>> >> >> >> -- >> -Calvin W. Metcalf >> >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> >> > -- -Calvin W. Metcalf -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140926/0cd71e51/attachment.html>
Theoretically you can use System.normalize() and System.get() to lookup a module by name synchronously. The normalize feature requires a referrer or address.
Since browsers are determined to eliminate synchronous scripts, you may as well deal with the asynchronous System.import() and obnoxious promises stuff now and save yourself some pain later.
Theoretically you can use System.normalize() and System.get() to lookup a module by name synchronously. The normalize feature requires a referrer or address. Since browsers are determined to eliminate synchronous scripts, you may as well deal with the asynchronous System.import() and obnoxious promises stuff now and save yourself some pain later. jjb On Fri, Sep 26, 2014 at 9:40 AM, Konstantin Ikonnikov <ikokostya at gmail.com> wrote: > I don't want load module using http request. In my case module already > defined and I want import it later when I get its name: > > ```js > var moduleName = getModuleName(); > import { foo } from moduleName; > > // use foo > ``` > > > > 2014-09-26 20:00 GMT+04:00 Marius Gundersen <gundersen at gmail.com>: > >> And the reason you cannot import a module synchronously is that it would >> freeze the entire browser until the http request completes, which could be >> several seconds on a slow internet connection. >> >> If you want to import something dynamically you can do it using the API >> (to be finalized, I believe): >> >> ```js >> var moduleName = 'foo'; >> Loader.import(moduleName).then(function(foo){ >> //use foo here >> }); >> ``` >> >> Marius Gundersen >> >> On Fri, Sep 26, 2014 at 5:29 PM, John Barton <johnjbarton at google.com> >> wrote: >> >>> no. >>> >>> On Fri, Sep 26, 2014 at 8:12 AM, Konstantin Ikonnikov < >>> ikokostya at gmail.com> wrote: >>> >>>> Can I import module dynamically, but synchronously? Example for common >>>> js >>>> >>>> ```js >>>> var moduleName = 'foo'; >>>> var foo = require(moduleName); >>>> ``` >>>> >>>> In es6 draft I found that ModuleSpecifier must be a StringLiteral >>>> http://people.mozilla.org/~jorendorff/es6-draft.html#sec-imports >>>> >>>> _______________________________________________ >>>> es-discuss mailing list >>>> es-discuss at mozilla.org >>>> https://mail.mozilla.org/listinfo/es-discuss >>>> >>>> >>> >>> _______________________________________________ >>> es-discuss mailing list >>> es-discuss at mozilla.org >>> https://mail.mozilla.org/listinfo/es-discuss >>> >>> >> > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140926/da2be922/attachment-0001.html>
I would like to see some way to preload everything, and be able to retrieve them synchronously, something like:
System.loader.addNoAsync('...'); // throw if all imports aren't available already
So that the script could be used during initial render. I understand that this would mean that the module would need to be parsed and executed synchronously. Forcing folks to never use any module for code that needs to be inline seems like a bad turn.
I would like to see some way to preload everything, and be able to retrieve them synchronously, something like: System.loader.addNoAsync('...'); // throw if all imports aren't available already So that the script could be used during initial render. I understand that this would mean that the module would need to be parsed and executed synchronously. Forcing folks to never use any module for code that needs to be inline seems like a bad turn. On Fri, Sep 26, 2014 at 1:44 PM, John Barton <johnjbarton at google.com> wrote: > Theoretically you can use System.normalize() and System.get() to lookup a > module by name synchronously. The normalize feature requires a referrer or > address. > > Since browsers are determined to eliminate synchronous scripts, you may as > well deal with the asynchronous System.import() and obnoxious promises > stuff now and save yourself some pain later. > > jjb > > On Fri, Sep 26, 2014 at 9:40 AM, Konstantin Ikonnikov <ikokostya at gmail.com > > wrote: > >> I don't want load module using http request. In my case module already >> defined and I want import it later when I get its name: >> >> ```js >> var moduleName = getModuleName(); >> import { foo } from moduleName; >> >> // use foo >> ``` >> >> >> >> 2014-09-26 20:00 GMT+04:00 Marius Gundersen <gundersen at gmail.com>: >> >>> And the reason you cannot import a module synchronously is that it would >>> freeze the entire browser until the http request completes, which could be >>> several seconds on a slow internet connection. >>> >>> If you want to import something dynamically you can do it using the API >>> (to be finalized, I believe): >>> >>> ```js >>> var moduleName = 'foo'; >>> Loader.import(moduleName).then(function(foo){ >>> //use foo here >>> }); >>> ``` >>> >>> Marius Gundersen >>> >>> On Fri, Sep 26, 2014 at 5:29 PM, John Barton <johnjbarton at google.com> >>> wrote: >>> >>>> no. >>>> >>>> On Fri, Sep 26, 2014 at 8:12 AM, Konstantin Ikonnikov < >>>> ikokostya at gmail.com> wrote: >>>> >>>>> Can I import module dynamically, but synchronously? Example for >>>>> common js >>>>> >>>>> ```js >>>>> var moduleName = 'foo'; >>>>> var foo = require(moduleName); >>>>> ``` >>>>> >>>>> In es6 draft I found that ModuleSpecifier must be a StringLiteral >>>>> http://people.mozilla.org/~jorendorff/es6-draft.html#sec-imports >>>>> >>>>> _______________________________________________ >>>>> es-discuss mailing list >>>>> es-discuss at mozilla.org >>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>> >>>>> >>>> >>>> _______________________________________________ >>>> es-discuss mailing list >>>> es-discuss at mozilla.org >>>> https://mail.mozilla.org/listinfo/es-discuss >>>> >>>> >>> >> >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> >> > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140927/6dce4e63/attachment.html>
From: es-discuss [mailto:es-discuss-bounces at mozilla.org] On Behalf Of John Lenz
I would like to see some way to preload everything, and be able to retrieve them synchronously, something like:
Sounds like a good custom loader extension that you could write.
From: es-discuss [mailto:es-discuss-bounces at mozilla.org] On Behalf Of John Lenz > I would like to see some way to preload everything, and be able to retrieve them synchronously, something like: Sounds like a good custom loader extension that you could write.
Note that of all you want is to load of it's already available, and fail otherwise, that's already provided. If what you want is sync io though, tc39 is not going to add it.
On Sep 28, 2014 1:07 AM, "Domenic Denicola" <domenic at domenicdenicola.com> wrote: > > From: es-discuss [mailto:es-discuss-bounces at mozilla.org] On Behalf Of John Lenz > > > I would like to see some way to preload everything, and be able to retrieve them synchronously, something like: > > Sounds like a good custom loader extension that you could write. Note that of all you want is to load of it's already available, and fail otherwise, that's already provided. If what you want is sync io though, tc39 is not going to add it. Sam -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140928/4d634677/attachment.html>
I'm confused. We went from bundled, synchronous modules to asynchronous modules... Why exactly?
And what about the offline case where modules are loaded from disk or are even complied into an archive file (for fast seek times on rotating disks)? Are those use cases not important to TC39?
Does the loader API handle all resources? Can I load other assets like images with it? Can I have one simple preloader for my game which says map_3 depends on these assets/modules/level scripts, and have ES6 take care of the rest?
I'm confused. We went from bundled, synchronous modules to asynchronous modules... Why exactly? And what about the offline case where modules are loaded from disk or are even complied into an archive file (for fast seek times on rotating disks)? Are those use cases not important to TC39? Does the loader API handle all resources? Can I load other assets like images with it? Can I have one simple preloader for my game which says map_3 depends on these assets/modules/level scripts, and have ES6 take care of the rest? On 28 Sep 2014 07:22, "Sam Tobin-Hochstadt" <samth at cs.indiana.edu> wrote: > > On Sep 28, 2014 1:07 AM, "Domenic Denicola" <domenic at domenicdenicola.com> > wrote: > > > > From: es-discuss [mailto:es-discuss-bounces at mozilla.org] On Behalf Of > John Lenz > > > > > I would like to see some way to preload everything, and be able to > retrieve them synchronously, something like: > > > > Sounds like a good custom loader extension that you could write. > > Note that of all you want is to load of it's already available, and fail > otherwise, that's already provided. If what you want is sync io though, > tc39 is not going to add it. > > Sam > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140928/2b9cf4b9/attachment-0001.html>
On 28 September 2014 07:01, John Lenz <concavelenz at gmail.com> wrote:
I would like to see some way to preload everything, and be able to retrieve them synchronously, something like:
System.loader.addNoAsync('...'); // throw if all imports aren't available already
So that the script could be used during initial render. I understand that this would mean that the module would need to be parsed and executed synchronously. Forcing folks to never use any module for code that needs to be inline seems like a bad turn.
I'm not sure what rendering behaviour is planned for <script type="module">, but I hope there would be a way to indicate when it should and shouldn't block rendering of the HTML page / HTML import.
In terms of preloading, there are complete ways to do this through custom extensions.
On 28 September 2014 07:01, John Lenz <concavelenz at gmail.com> wrote: > I would like to see some way to preload everything, and be able to > retrieve them synchronously, something like: > > System.loader.addNoAsync('...'); // throw if all imports aren't > available already > > So that the script could be used during initial render. I understand that > this would mean that the module would need to be parsed and executed > synchronously. Forcing folks to never use any module for code that needs to > be inline seems like a bad turn. > I'm not sure what rendering behaviour is planned for <script type="module">, but I hope there would be a way to indicate when it should and shouldn't block rendering of the HTML page / HTML import. In terms of preloading, there are complete ways to do this through custom extensions. > > On Fri, Sep 26, 2014 at 1:44 PM, John Barton <johnjbarton at google.com> > wrote: > >> Theoretically you can use System.normalize() and System.get() to lookup a >> module by name synchronously. The normalize feature requires a referrer or >> address. >> >> Since browsers are determined to eliminate synchronous scripts, you may >> as well deal with the asynchronous System.import() and obnoxious promises >> stuff now and save yourself some pain later. >> >> jjb >> >> On Fri, Sep 26, 2014 at 9:40 AM, Konstantin Ikonnikov < >> ikokostya at gmail.com> wrote: >> >>> I don't want load module using http request. In my case module already >>> defined and I want import it later when I get its name: >>> >>> ```js >>> var moduleName = getModuleName(); >>> import { foo } from moduleName; >>> >>> // use foo >>> ``` >>> >>> >>> >>> 2014-09-26 20:00 GMT+04:00 Marius Gundersen <gundersen at gmail.com>: >>> >>>> And the reason you cannot import a module synchronously is that it >>>> would freeze the entire browser until the http request completes, which >>>> could be several seconds on a slow internet connection. >>>> >>>> If you want to import something dynamically you can do it using the API >>>> (to be finalized, I believe): >>>> >>>> ```js >>>> var moduleName = 'foo'; >>>> Loader.import(moduleName).then(function(foo){ >>>> //use foo here >>>> }); >>>> ``` >>>> >>>> Marius Gundersen >>>> >>>> On Fri, Sep 26, 2014 at 5:29 PM, John Barton <johnjbarton at google.com> >>>> wrote: >>>> >>>>> no. >>>>> >>>>> On Fri, Sep 26, 2014 at 8:12 AM, Konstantin Ikonnikov < >>>>> ikokostya at gmail.com> wrote: >>>>> >>>>>> Can I import module dynamically, but synchronously? Example for >>>>>> common js >>>>>> >>>>>> ```js >>>>>> var moduleName = 'foo'; >>>>>> var foo = require(moduleName); >>>>>> ``` >>>>>> >>>>>> In es6 draft I found that ModuleSpecifier must be a StringLiteral >>>>>> http://people.mozilla.org/~jorendorff/es6-draft.html#sec-imports >>>>>> >>>>>> _______________________________________________ >>>>>> es-discuss mailing list >>>>>> es-discuss at mozilla.org >>>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>>> >>>>>> >>>>> >>>>> _______________________________________________ >>>>> es-discuss mailing list >>>>> es-discuss at mozilla.org >>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>> >>>>> >>>> >>> >>> _______________________________________________ >>> es-discuss mailing list >>> es-discuss at mozilla.org >>> https://mail.mozilla.org/listinfo/es-discuss >>> >>> >> >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> >> > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140928/073ae990/attachment-0001.html>
Also you CAN potentially do something like this eventually:
(async function() {
var myMod = await System.import("my-mod");
})()
Also you CAN potentially do something like this eventually: ``` (async function() { var myMod = await System.import("my-mod"); })() ``` - Matthew Robb On Sun, Sep 28, 2014 at 11:45 AM, Guy Bedford <guybedford at gmail.com> wrote: > On 28 September 2014 07:01, John Lenz <concavelenz at gmail.com> wrote: > >> I would like to see some way to preload everything, and be able to >> retrieve them synchronously, something like: >> >> System.loader.addNoAsync('...'); // throw if all imports aren't >> available already >> >> So that the script could be used during initial render. I understand that >> this would mean that the module would need to be parsed and executed >> synchronously. Forcing folks to never use any module for code that needs to >> be inline seems like a bad turn. >> > > I'm not sure what rendering behaviour is planned for <script > type="module">, but I hope there would be a way to indicate when it should > and shouldn't block rendering of the HTML page / HTML import. > > In terms of preloading, there are complete ways to do this through custom > extensions. > > >> >> On Fri, Sep 26, 2014 at 1:44 PM, John Barton <johnjbarton at google.com> >> wrote: >> >>> Theoretically you can use System.normalize() and System.get() to lookup >>> a module by name synchronously. The normalize feature requires a referrer >>> or address. >>> >>> Since browsers are determined to eliminate synchronous scripts, you may >>> as well deal with the asynchronous System.import() and obnoxious promises >>> stuff now and save yourself some pain later. >>> >>> jjb >>> >>> On Fri, Sep 26, 2014 at 9:40 AM, Konstantin Ikonnikov < >>> ikokostya at gmail.com> wrote: >>> >>>> I don't want load module using http request. In my case module already >>>> defined and I want import it later when I get its name: >>>> >>>> ```js >>>> var moduleName = getModuleName(); >>>> import { foo } from moduleName; >>>> >>>> // use foo >>>> ``` >>>> >>>> >>>> >>>> 2014-09-26 20:00 GMT+04:00 Marius Gundersen <gundersen at gmail.com>: >>>> >>>>> And the reason you cannot import a module synchronously is that it >>>>> would freeze the entire browser until the http request completes, which >>>>> could be several seconds on a slow internet connection. >>>>> >>>>> If you want to import something dynamically you can do it using the >>>>> API (to be finalized, I believe): >>>>> >>>>> ```js >>>>> var moduleName = 'foo'; >>>>> Loader.import(moduleName).then(function(foo){ >>>>> //use foo here >>>>> }); >>>>> ``` >>>>> >>>>> Marius Gundersen >>>>> >>>>> On Fri, Sep 26, 2014 at 5:29 PM, John Barton <johnjbarton at google.com> >>>>> wrote: >>>>> >>>>>> no. >>>>>> >>>>>> On Fri, Sep 26, 2014 at 8:12 AM, Konstantin Ikonnikov < >>>>>> ikokostya at gmail.com> wrote: >>>>>> >>>>>>> Can I import module dynamically, but synchronously? Example for >>>>>>> common js >>>>>>> >>>>>>> ```js >>>>>>> var moduleName = 'foo'; >>>>>>> var foo = require(moduleName); >>>>>>> ``` >>>>>>> >>>>>>> In es6 draft I found that ModuleSpecifier must be a StringLiteral >>>>>>> http://people.mozilla.org/~jorendorff/es6-draft.html#sec-imports >>>>>>> >>>>>>> _______________________________________________ >>>>>>> es-discuss mailing list >>>>>>> es-discuss at mozilla.org >>>>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>>>> >>>>>>> >>>>>> >>>>>> _______________________________________________ >>>>>> es-discuss mailing list >>>>>> es-discuss at mozilla.org >>>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>>> >>>>>> >>>>> >>>> >>>> _______________________________________________ >>>> es-discuss mailing list >>>> es-discuss at mozilla.org >>>> https://mail.mozilla.org/listinfo/es-discuss >>>> >>>> >>> >>> _______________________________________________ >>> es-discuss mailing list >>> es-discuss at mozilla.org >>> https://mail.mozilla.org/listinfo/es-discuss >>> >>> >> >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> >> > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140928/f72e2c41/attachment-0001.html>
What is wrong with Loader.get()?
Reflect.Loader.prototype.get ( name )
If this Loader's module registry contains a Module with the given normalized name, return it. Otherwise, return undefined. If the module is in the registry but has never been evaluated, first synchronously evaluate the bodies of the module and any dependencies that have not evaluated yet.
But more important perhaps, what is wrong with asynchronous loads? The System.import() promises a module after loading all of its dependencies; previously imported modules are not reloaded. This code can be used in development, then in production the bundled modules can be prefixed to load the registry and the same call executes the same app. If this scheme is not going to work now is the time to sort it out.
What is wrong with Loader.get()? ------- Reflect.Loader.prototype.get ( name )If this Loader's module registry contains a Module with the given normalized name, return it. Otherwise, return undefined. If the module is in the registry but has never been evaluated, first synchronously evaluate the bodies of the module and any dependencies that have not evaluated yet. But more important perhaps, what is wrong with asynchronous loads? The System.import() promises a module after loading all of its dependencies; previously imported modules are not reloaded. This code can be used in development, then in production the bundled modules can be prefixed to load the registry and the same call executes the same app. If this scheme is not going to work now is the time to sort it out. jjb On Sat, Sep 27, 2014 at 10:01 PM, John Lenz <concavelenz at gmail.com> wrote: > I would like to see some way to preload everything, and be able to > retrieve them synchronously, something like: > > System.loader.addNoAsync('...'); // throw if all imports aren't > available already > > So that the script could be used during initial render. I understand that > this would mean that the module would need to be parsed and executed > synchronously. Forcing folks to never use any module for code that needs to > be inline seems like a bad turn. > > On Fri, Sep 26, 2014 at 1:44 PM, John Barton <johnjbarton at google.com> > wrote: > >> Theoretically you can use System.normalize() and System.get() to lookup a >> module by name synchronously. The normalize feature requires a referrer or >> address. >> >> Since browsers are determined to eliminate synchronous scripts, you may >> as well deal with the asynchronous System.import() and obnoxious promises >> stuff now and save yourself some pain later. >> >> jjb >> >> On Fri, Sep 26, 2014 at 9:40 AM, Konstantin Ikonnikov < >> ikokostya at gmail.com> wrote: >> >>> I don't want load module using http request. In my case module already >>> defined and I want import it later when I get its name: >>> >>> ```js >>> var moduleName = getModuleName(); >>> import { foo } from moduleName; >>> >>> // use foo >>> ``` >>> >>> >>> >>> 2014-09-26 20:00 GMT+04:00 Marius Gundersen <gundersen at gmail.com>: >>> >>>> And the reason you cannot import a module synchronously is that it >>>> would freeze the entire browser until the http request completes, which >>>> could be several seconds on a slow internet connection. >>>> >>>> If you want to import something dynamically you can do it using the API >>>> (to be finalized, I believe): >>>> >>>> ```js >>>> var moduleName = 'foo'; >>>> Loader.import(moduleName).then(function(foo){ >>>> //use foo here >>>> }); >>>> ``` >>>> >>>> Marius Gundersen >>>> >>>> On Fri, Sep 26, 2014 at 5:29 PM, John Barton <johnjbarton at google.com> >>>> wrote: >>>> >>>>> no. >>>>> >>>>> On Fri, Sep 26, 2014 at 8:12 AM, Konstantin Ikonnikov < >>>>> ikokostya at gmail.com> wrote: >>>>> >>>>>> Can I import module dynamically, but synchronously? Example for >>>>>> common js >>>>>> >>>>>> ```js >>>>>> var moduleName = 'foo'; >>>>>> var foo = require(moduleName); >>>>>> ``` >>>>>> >>>>>> In es6 draft I found that ModuleSpecifier must be a StringLiteral >>>>>> http://people.mozilla.org/~jorendorff/es6-draft.html#sec-imports >>>>>> >>>>>> _______________________________________________ >>>>>> es-discuss mailing list >>>>>> es-discuss at mozilla.org >>>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>>> >>>>>> >>>>> >>>>> _______________________________________________ >>>>> es-discuss mailing list >>>>> es-discuss at mozilla.org >>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>> >>>>> >>>> >>> >>> _______________________________________________ >>> es-discuss mailing list >>> es-discuss at mozilla.org >>> https://mail.mozilla.org/listinfo/es-discuss >>> >>> >> >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140928/c4a038d0/attachment.html>
What is wrong with asynchronous loads other than the fact that they can't be used in synchronous algorithms, you mean? (i.e. the vast majority of existing software)
That seems to be the motive: Not synchronous network or disk i/o, just synchronous import. I can see how there's perhaps a moral argument to be made about why that shouldn't be possible.
I guess if you use the loader api to synchronously fetch an existing module, all you have to do is manually implement the 'import' part yourself by pulling names out of it and into the current namespace.
What is wrong with asynchronous loads other than the fact that they can't be used in synchronous algorithms, you mean? (i.e. the vast majority of existing software) That seems to be the motive: Not synchronous network or disk i/o, just synchronous import. I can see how there's perhaps a moral argument to be made about why that shouldn't be possible. I guess if you use the loader api to synchronously fetch an existing module, all you have to do is manually implement the 'import' part yourself by pulling names out of it and into the current namespace. On Sun, Sep 28, 2014 at 10:41 AM, John Barton <johnjbarton at google.com> wrote: > What is wrong with Loader.get()? > ------- > Reflect.Loader.prototype.get ( name ) > > If this Loader's module registry contains a Module with the given normalized > name, return it. Otherwise, return undefined. If the module is in the > registry but has never been evaluated, first synchronously evaluate the > bodies of the module and any dependencies that have not evaluated yet. > > But more important perhaps, what is wrong with asynchronous loads? The > System.import() promises a module after loading all of its dependencies; > previously imported modules are not reloaded. This code can be used in > development, then in production the bundled modules can be prefixed to load > the registry and the same call executes the same app. If this scheme is not > going to work now is the time to sort it out. > > jjb > > > On Sat, Sep 27, 2014 at 10:01 PM, John Lenz <concavelenz at gmail.com> wrote: >> >> I would like to see some way to preload everything, and be able to >> retrieve them synchronously, something like: >> >> System.loader.addNoAsync('...'); // throw if all imports aren't >> available already >> >> So that the script could be used during initial render. I understand that >> this would mean that the module would need to be parsed and executed >> synchronously. Forcing folks to never use any module for code that needs to >> be inline seems like a bad turn. >> >> On Fri, Sep 26, 2014 at 1:44 PM, John Barton <johnjbarton at google.com> >> wrote: >>> >>> Theoretically you can use System.normalize() and System.get() to lookup a >>> module by name synchronously. The normalize feature requires a referrer or >>> address. >>> >>> Since browsers are determined to eliminate synchronous scripts, you may >>> as well deal with the asynchronous System.import() and obnoxious promises >>> stuff now and save yourself some pain later. >>> >>> jjb >>> >>> On Fri, Sep 26, 2014 at 9:40 AM, Konstantin Ikonnikov >>> <ikokostya at gmail.com> wrote: >>>> >>>> I don't want load module using http request. In my case module already >>>> defined and I want import it later when I get its name: >>>> >>>> ```js >>>> var moduleName = getModuleName(); >>>> import { foo } from moduleName; >>>> >>>> // use foo >>>> ``` >>>> >>>> >>>> >>>> 2014-09-26 20:00 GMT+04:00 Marius Gundersen <gundersen at gmail.com>: >>>>> >>>>> And the reason you cannot import a module synchronously is that it >>>>> would freeze the entire browser until the http request completes, which >>>>> could be several seconds on a slow internet connection. >>>>> >>>>> If you want to import something dynamically you can do it using the API >>>>> (to be finalized, I believe): >>>>> >>>>> ```js >>>>> var moduleName = 'foo'; >>>>> Loader.import(moduleName).then(function(foo){ >>>>> //use foo here >>>>> }); >>>>> ``` >>>>> >>>>> Marius Gundersen >>>>> >>>>> On Fri, Sep 26, 2014 at 5:29 PM, John Barton <johnjbarton at google.com> >>>>> wrote: >>>>>> >>>>>> no. >>>>>> >>>>>> On Fri, Sep 26, 2014 at 8:12 AM, Konstantin Ikonnikov >>>>>> <ikokostya at gmail.com> wrote: >>>>>>> >>>>>>> Can I import module dynamically, but synchronously? Example for >>>>>>> common js >>>>>>> >>>>>>> ```js >>>>>>> var moduleName = 'foo'; >>>>>>> var foo = require(moduleName); >>>>>>> ``` >>>>>>> >>>>>>> In es6 draft I found that ModuleSpecifier must be a StringLiteral >>>>>>> http://people.mozilla.org/~jorendorff/es6-draft.html#sec-imports >>>>>>> >>>>>>> _______________________________________________ >>>>>>> es-discuss mailing list >>>>>>> es-discuss at mozilla.org >>>>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>>>> >>>>>> >>>>>> >>>>>> _______________________________________________ >>>>>> es-discuss mailing list >>>>>> es-discuss at mozilla.org >>>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>>> >>>>> >>>> >>>> >>>> _______________________________________________ >>>> es-discuss mailing list >>>> es-discuss at mozilla.org >>>> https://mail.mozilla.org/listinfo/es-discuss >>>> >>> >>> >>> _______________________________________________ >>> es-discuss mailing list >>> es-discuss at mozilla.org >>> https://mail.mozilla.org/listinfo/es-discuss >>> >> > > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss >
Can I import module dynamically, but synchronously? Example for common js
var moduleName = 'foo'; var foo = require(moduleName);
In es6 draft I found that ModuleSpecifier must be a StringLiteral people.mozilla.org/~jorendorff/es6-draft.html#sec