Standard modules - concept or concrete?

Sam Tobin-Hochstadt samth at ccs.neu.edu
Fri Jun 21 05:50:30 PDT 2013


On Jun 20, 2013 7:53 PM, "James Burke" <jrburke at gmail.com> wrote:
>
> On Thu, Jun 20, 2013 at 9:08 AM, Sam Tobin-Hochstadt <samth at ccs.neu.edu>
wrote:
> > On Thu, Jun 20, 2013 at 10:26 AM, Kevin Smith <zenparsing at gmail.com>
wrote:
> >> I wonder, though, if this might create issues for polyfilling:
> >>
> >>     // polyfillz.js
> >>     if (this.Promise ===  void 0)
> >>         this.Promise = function() { ... }
> >>
> >>     // main.js
> >>     import "polyfillz.js";
> >>     new Promise();
> >>
> >> This would refuse to compile, right?  We'd have to introduce all of our
> >> polyfills in a separate (previous) compilation/execution cycle.
> >
> > Yes, like so:
> >
> >     <script src="polyfillz.js"/>
> >
> > Note that this is already the way people suggest using polyfills; see
> > [1] for an example.
>
> I have found that once I have module loading, I want the dependencies
> to be specified by the modules that use them, either via the
> declarative dependency syntax or via module loader APIs, and at the
> very least, avoid script tags as the optimization tools can work
> solely by tracing module/JS loading APIs. In this case, only the
> "model" set of modules would care about setting up indexeddb access,
> not the top level of the app.
>
> Example, this AMD module:
>
> https://github.com/jrburke/carmino/blob/master/www/lib/IDB.js
>
> Asks for "indexedDB!", which is an AMD loader plugin:
>
> https://github.com/jrburke/carmino/blob/master/www/lib/indexedDB.js
>
> which feature detects and uses a module loader API to load a shim if
> it is needed. So the "IDB" module will not execute until that optional
> shim work is done.
>
> I believe this will also work via the ES Module Loader API, but
> calling it out just in case I missed something. I want to be sure
> there are options that do not require using <script src> tags, except
> maybe one to bootstrap a set of Module Loader hooks.

Yes, this will work fine. Loader hooks can explicitly add modules using the
loader API, allowing them to polyfill in exactly this way.

Sam
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130621/9e971962/attachment-0001.html>


More information about the es-discuss mailing list