Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asynchronous module loading #30

Open
5 tasks
divmain opened this issue Aug 29, 2015 · 0 comments
Open
5 tasks

Asynchronous module loading #30

divmain opened this issue Aug 29, 2015 · 0 comments
Assignees

Comments

@divmain
Copy link
Member

divmain commented Aug 29, 2015

Add feature similar to require.ensure, but call it require.async.

  • These function calls should be detected in much the same way as require(...) calls.
  • Modules should still be recursively discovered and included in build.
  • Build-time behavior should be identical - require.async has no effect on splitting. That is still managed by the build config itself.
  • Run-time behavior is different - module is not included in dependencies hash, and is not guaranteed to have been invoked prior to containing module.
  • When require.async (or compiled equivalent) is invoked at run-time, 1) modules are resolved and invoked, 2) callback is invoked with params matching the required modules.

Example input

const libA = require("./lib-a");
require.async(["./lib-b", "./lib-c"], function (libB, libC) {
  // ...
});

Example output

{
  'aaaaaa': {
    deps: [],
    fn: function (require, module, exports) {
      var libA = require("bbbbbb")
      require.async("cccccc"/*["dddddd", "eeeeee"]*/, function (libB, libC) {
        // ...
      });
    }
  },
  'bbbbbb': {
    deps: [],
    fn: function (require, module, exports) {
      module.exports = "libA";
    }
  },
  'cccccc': {
    deps: ["dddddd", "eeeeee"],
    fn: function (require, module, exports) {
      module.exports = function (cb) {
        cb(require("dddddd"), require("eeeeee"));
      };
    }
  },
  'dddddd': {
    deps: [],
    fn: function (require, module, exports) {
      module.exports = "libB";
    }
  },
  'eeeeee': {
    deps: [],
    fn: function (require, module, exports) {
      module.exports = "libC";
    }
  }
}

When the require.async is invoked within the example module, the Interlock will call the cccccc module as if it were an entry point - first ensuring that all dependencies are installed and invoked, resolving/installing/invoking any missing dependencies, and finally calling the cccccc module itself. This module's exports will be a function that invokes a callback, requiring and passing constituent dependencies as parameters.

The require.async implementation will have recorded the callback passed to it, and pass that to cccccc's returned function when available.

@divmain divmain added this to the v1.0 milestone Aug 29, 2015
@divmain divmain mentioned this issue Aug 29, 2015
61 tasks
@divmain divmain added the next label Sep 2, 2015
@divmain divmain self-assigned this Sep 2, 2015
@divmain divmain removed this from the v1.0 milestone Mar 12, 2016
@divmain divmain added in progress and removed next labels Jul 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant