Futures (was: Request for JSON-LD API review)

Ron Buckton rbuckton at chronicles.org
Tue Apr 23 18:27:46 PDT 2013


Other than the Future polyfill all it does is roughly this:

            // extract the indices for built-in dependencies
            if ((exportsIndex = dependencies.indexOf("exports")) > -1) dependencies.splice(exportsIndex, 1);
            if ((moduleIndex = dependencies.indexOf("module")) > -1) dependencies.splice(moduleIndex, 1);
            if ((requireIndex = dependencies.indexOf("require")) > -1) dependencies.splice(requireIndex, 1);

            // ... other stuff

           // load and wait for all dependencies
            Future.every
                .apply(null, dependencies.map(load))
                .then(function (imports) {
                    var exports = {};

                    // reapply the built-in dependencies if requested.
                    if (requireIndex > -1) imports.splice(requireIndex, 0, require);
                    if (moduleIndex > -1) imports.splice(moduleIndex, 0, config);
                    if (exportsIndex > -1) imports.splice(exportsIndex, 0, exports);

                    if (typeof factory === "function") {
                        var result = factory.apply(null, imports);
                        if (result) {
                            exports = result;
                        }
                        else if (config.exports) {
                            exports = config.exports;
                        }
                    }
                    else if (factory) {
                        exports = factory;
                    }
                    resolver.resolve(exports);
                })
                .catch(resolver.reject)
                .done();

Though there's more to it to handle things like module concatenation, etc.

Ron

From: Mark S. Miller [mailto:erights at google.com]
Sent: Tuesday, April 23, 2013 5:33 PM
To: Ron Buckton
Cc: Tab Atkins Jr.; es-discuss
Subject: Re: Futures (was: Request for JSON-LD API review)

On Tue, Apr 23, 2013 at 5:16 PM, Ron Buckton <rbuckton at chronicles.org<mailto:rbuckton at chronicles.org>> wrote:
> [...] a Future-based AMD module loader I'm tinkering with.

In that case, you might want to look at <http://wiki.ecmascript.org/doku.php?id=strawman:concurrency#amd_loader_lite> and <https://code.google.com/p/google-caja/source/browse/trunk/src/com/google/caja/ses/makeSimpleAMDLoader.js>.

--
    Cheers,
    --MarkM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130424/308b7c32/attachment-0001.html>


More information about the es-discuss mailing list