On Jan 27, 2011, at 12:26 PM, Wes Garland wrote:

> On Thu, Jan 27, 2011 at 12:37 PM, David Herman <dher...@mozilla.com> wrote:
> Or here's a sort of more operational way to think about it: Start with the 
> outermost program. It declares a bunch of modules, some of which are loaded 
> from external files. [.....]
> 
> And one more key difference from CommonJS that's worth pointing out -- Simple 
> Modules are not singletons, so if two modules include the same dependency, we 
> get two instances of the dependency, right?

Well, first let me clarify a bit. We distinguish between module locations (aka 
MRL's aka URL's), loaded via:

    module m = "foo/bar/baz.js";

and module bindings, which are simply referred to via ordinary lexical scope. 
Multiple references to the same module binding use the same shared instance, 
and importing bindings from the same module binding in multiple places also 
uses the same shared instance. It's only the module load syntax above that 
causes multiple loads.

That said, I've been talking with Sam about this, and I think we can do a bit 
better. It should be possible to allow module loaders to selectively 
canonicalize MRL's, so that they could be shared. This would make the module 
load syntax more conveniently amenable to the server side; the system module 
loader for, say, Node.js, could canonicalize all paths on the file system, so 
that if you load "foo/bar/baz.js" multiple times you get a shared instance.

As I say, we've been talking about this and working through some of the 
details, and we'll write up more on the wiki.

> IIUC (confirm please?), this is also another significant difference between 
> the two worlds in terms of module initialization.  It makes the "correctness 
> graph" in Simple Modules easier to reason about by removing non-determinism 
> around first-time-use.

On the client side, URL's aren't canonicalized to produce singleton instances. 
That said, I believe even with allowing module loaders to provide selective 
canonicalization, we can do so without non-determinism around first-time-use. 
More soon.

Dave

_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to