jquery/jquery-mobile — Issue #3386: Updates for AMD
Author: jrburke
Created: 2012-01-05 19:57:05+00:00
State: open

I'm not sure if this is the right place for this, I did not find an existing bug or forum entry. So feel free to redirect me to the right place.

The AMD support is cool. I'm wondering about some of the design motivations for using it. I would have originally suggested the following design (using jquery.mobile.forms.button.js as an example):

Use a define call that specfies jQuery as a dependency, and then removing the inner anonymous function and pragmas:

```javascript
define(["jquery", "jquery.mobile.widget", "jquery.mobile.buttonMarkup" ], function($, undefined) {
$.widget( "mobile.button", $.mobile.widget, {});
});
```javascript

then as part of the build output provide a function wrapper around the full build output with a tiny define shim inside:

```javascript
function define(args, factory) { factory(jQuery); }
```

This would cut down on the two levels of function(){} nesting in a module, and make sure that each module can stand on its own (specifies jQuery as a dependency). It would also remove the pragmas, which are a bit wordy.

If you are concerned about having the extra strings in the define[] calls for dependencies after a build, then I would do a regexp to remove them in a post build process.

But I am not sure about the design goals and what other factors are in play. I'm happy to do a pull request that does the above approach though if it seems like it might be desirable.