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

Remove per-extension AMD loader #15

Open
Osmose opened this issue Jul 1, 2012 · 0 comments
Open

Remove per-extension AMD loader #15

Osmose opened this issue Jul 1, 2012 · 0 comments

Comments

@Osmose
Copy link
Contributor

Osmose commented Jul 1, 2012

Currently, each gladius extension includes its own version of almond.js, which means that each extension is using its own AMD loader. As a result, each extension needs to include code from gladius-core that it uses, resulting in possibly-out-of-date code being used and extra code lying around.

This is, IMO, one of the most important things to fix about gladius, as it is very very likely to break behavior between extensions, and makes using gladius for a game awkward.

One solution I can think of is attaching the almond.js functions define and require to the Gladius object and having the extensions pull them in within their wrapper:

(function( root, factory ) {

  if (typeof exports === "object") {
    // Node
    module.exports = factory(require, define);
  } else if (typeof define === "function" && define.amd) {
    // AMD. Register as an anonymous module.
    define(factory.bind(undefined, require, define));
  } else if( root.Gladius ) {
    // Browser globals
    var amd = root.Gladius.amd;
    root.Gladius["gladius-cubicvr"] = factory(amd.require, amd.define);
  } else {
    throw new Error( "failed to load gladius-cubicvr; depends on Gladius" );
  }

}( this, function(require, define) {

// ...

  var extension = require( "gladius/cubicvr" );

  return extension;

}));
  • The snippet above is untested, mostly looking for feedback before seeing if it'd actually work. I think it should work.
  • The gladius/cubicvr thing above should be achievable with some path magic, especially now that lib doesn't need to be included during the build step for extensions.
  • While we're at it, we should make that wrapper automatically load the extension into Gladius. :D

This way we get a project-wide benefit of using AMD without repeating code, yet still don't depend on the outside world to use an AMD loader.

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