On Fri, Nov 5, 2010 at 2:47 PM, Kris Zyp <[email protected]> wrote:
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
>
>
> On 11/5/2010 12:31 PM, Sam Tobin-Hochstadt wrote:
>> On Fri, Nov 5, 2010 at 2:25 PM, Kris Zyp <[email protected]> wrote:
>>>
>>> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
>>>
>>> Another idea that might provide the extensibility to deal with
>>> loading various resources and alternate/older modules, what if we
>>> added the ability to specify the loader to use for a module:
>>
>> This is of course possible with a module loader, and these are
>> interesting and valuable use cases.
>
> Right, but how does a module express a dependence on a particular
> module loader? The problem is that it requires knowledge of what
> module loader is needed, and this must be manually loaded before hand,
> which is problem that modules is supposed to solve.

Modules don't and shouldn't get to specify their loader - the whole
point of module loaders is for the load*er*, not the loadee, to
specify the semantics.

If you want to load a data file using a special loader, you'd do it like this:

let ld = new TextModuleLoader();
ld.loadModule(['Template', 'template.html'] function (templ) { ... });

If you need to obtain TextModuleLoader async as well, that can be
arranged in the same fashion.

>>> module myApp { module Template = load "template.html" with
>>> "text-loader.js"; // load a template text module Messages = load
>>> "messages.json" with "i18n.js"; // load some messages module
>>> OldModule = load "old-module.js" with "commonjs-loader.js";
>>> module NewShiny = load "a-harmony-module.js"; // use the default
>>> native harmony module loader ...
>>
>> But I don't think using the declarative syntax for this is a good
>> idea - there's no static scope here; instead, there's arbitrary
>> code execution and evaluation. Additionally, this makes
>> everything synchronous.
>
> Doesn't the default module loader get executed normally? Why do
> alternate module loaders change that? Why does it have to be
> synchronous, the module loader API is asynchronous?

The default module loader gets executed if you say "load".  Alternate
module loaders don't change that - using module loaders explicitly
allows changing that.

The declarative syntax is synchronous because the JS run-to-completion
semantics prohibits any other behavior.
-- 
sam th
[email protected]
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to