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 <concavel...@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 <johnjbar...@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 <
>> ikokos...@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 <gunder...@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 <johnjbar...@google.com>
>>>> wrote:
>>>>
>>>>> no.
>>>>>
>>>>> On Fri, Sep 26, 2014 at 8:12 AM, Konstantin Ikonnikov <
>>>>> ikokos...@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@mozilla.org
>>>>>> https://mail.mozilla.org/listinfo/es-discuss
>>>>>>
>>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> 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
>>>
>>>
>>
>> _______________________________________________
>> 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

Reply via email to