Skip to content

Instantly share code, notes, and snippets.

@justinbmeyer
Created May 10, 2012 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinbmeyer/2655173 to your computer and use it in GitHub Desktop.
Save justinbmeyer/2655173 to your computer and use it in GitHub Desktop.
AMD 2.0

Problems with the AMD:

Types require plugins

require(['css!style.css','ejs!template.ejs'], function(){})

I probably don't have to say anymore about this.

Doesn't work well with foder-based organization

When developing components, it's likely that a single component will have several parts, including:

  • templates
  • styles
  • tests

It's best for development to keep them all in one place, within a folder that contains the name of the component like:

app\
  component\
    component.js
    component.css
    template1.ejs
    template2.ejs
    component_test.js

However, this is awkward when using AMD. You have to either:

  • name app/component app/component/component, which is not how you'd want to share it
  • configure app/component to sit in app/component/component.js and in component.js make sure there's a define('app/component', .... ).

Unnecessary []

[] are only necessary when providing a definition, often this can, and should be determined from the path.

Solutions

types/plugins can be inferred from the suffix:

require(['style.css','template.ejs'], function(){})

For odd extensions, an object is accepted:

require([{type: "css", id: "my.style"}], function(){})

No "." looks in the folder

require(["foo/bar"])

Looks up in foo/bar/bar.js

Make it so [] doesn't always have to be used

require("foo/bar", function(){})

define("abc/def", function(){}) // definition is implied by path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment