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

Alternate manifest using regexes to drive it #23

Closed
jakobo opened this issue Nov 16, 2011 · 2 comments
Closed

Alternate manifest using regexes to drive it #23

jakobo opened this issue Nov 16, 2011 · 2 comments
Assignees
Milestone

Comments

@jakobo
Copy link
Contributor

jakobo commented Nov 16, 2011

Through conversation with @PeterFrueh, jquery's UI modules are difficult to load. In theory, we should be able to maintain the standard syntax:

$ = require("jQuery");
require("jquery.ui.core");
require("jquery.ui.mouse");
require("jquery.ui.widget");
require("jquery.ui.draggable");
// ... continue using $ normally

The limitations we are facing are best summed up as:

  1. the jQuery UI objects look for jQuery in the global context. Because of require sandboxing, this isn't available by default. We could solve this by using the pointcuts syntax, but that yields issue 2 below
  2. The current syntax doesn't allow for an easy way to package this up. You'd end up with a huge manifest, when really all you need is smarter regex rules

The result of this is a proposal for a new syntax that would deprecate require.manifest in favor of simpler additive rules

require.addRule(regex|string, [weight], {
  path: function() {} | string
  pointcuts: {
    before: function() {},
    after: function() {}
  }
});
@ghost ghost assigned jakobo Nov 16, 2011
@jakobo
Copy link
Contributor Author

jakobo commented Nov 16, 2011

Some considerations:

  • total time to run matches would be n regex/string checks
  • if you find a match, do you abort early, or do you continue down the stack? On one hand, continuing down the stack is pretty powerful as far as matching rules go. On the other, that's a ton of overhead potentially.
  • weight is listed as optional. Should faux-constants be created under require.CONSTANTS, or should we leave it up to the developer to weight their rules accordingly. By default, later rules would receive a higher index if not overridden.

@jakobo
Copy link
Contributor Author

jakobo commented Nov 22, 2011

I pieced together a sample bit of code for what including jquery might look like. My biggest concern is the addRule still feels pretty unwieldy for the more robust examples. It's certainly better than having dozens of repeated code lines though for each jQuery UI module.

    require.setModuleRoot("http://localhost:4000/deps");
    require.addRule(/^jquery$/, "jquery-1.7.js");
    require.addRule(/jquery\.ui/, {
      path: function(module) {
        return ["jqueryui", module].join("/") + ".min.js"
      },
      pointcuts: {
        before: function() {
          var jQuery = require("jquery");
        }
        after: function() {
          module.setExports(jQuery);
        }
      }
    });

@jakobo jakobo mentioned this issue Nov 23, 2011
jakobo pushed a commit that referenced this issue Dec 1, 2011
addRule prototype complete. #23
@jakobo jakobo closed this as completed Dec 1, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant