Skip to content

Remove per-extension AMD loader #15

Open
@Osmose

Description

@Osmose

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions