quirkey / sammy

Sammy is a tiny javascript framework built on top of jQuery, It's RESTful Evented Javascript.
http://sammyjs.org
MIT License
2.99k stars 384 forks source link

Made compliant with AMD loaders with global fallback #132

Closed mtscout6 closed 12 years ago

mtscout6 commented 12 years ago

Made compatible with AMD loaders following the Universal Module Definition pattern as laid out by @jrburke at https://github.com/umdjs/umd

For detailed description of what AMD is See: http://addyosmani.com/writing-modular-js/

quirkey commented 12 years ago

I would really like to pull this but the full file indentation change is going to break some meaningful git history or make it a bit more difficult to parse. Could you add the AMD header/wrapper at the top without changing the rest of the file?

mtscout6 commented 12 years ago

Not a problem. I just did a forced update to replace what I did have up there with the non-tabbed as you would like.

quirkey commented 12 years ago

Thanks! Way easier :)

rikkert commented 12 years ago

I figured to also make all the plugins AMD compliant.

If anyone needs a simple workaround when using Sammy as AMD module and using plugins, do the following. Before requiring any plugins:

  // plugins do Sammy = Sammy || {} instead of Sammy = window.Sammy
  Sammy = {};

Before starting the app merge the loaded plugins:

require(['jquery', 'sammy', 'plugins/sammy.googleanalytics', function($, sammy) {
  $.extend(sammy, window.Sammy);
  var app = sammy('#app', function() {
  // Plugins
  this.use('GoogleAnalytics');
}
dvdotsenko commented 12 years ago

@rikkert how does it resolve the issue of multiple anonymous defines when plugins are concatenaned to sammy and minified? As mentioned above, r.js cannot concatenate require or define with variable-based dependency lists.

Having separate Sammy builds - standard and AMD-enabled Seems like the safest solution, as if you look at the AMD drama Underscore went through, AMDing a base lib conjures up a storm and allergic reaction to AMD. with separate but official AMD build, when AMD will fall out of style in a year, Sammy's maintainer will not be stuck supporting it in mainline version. Keeping the AMD wrapper a build-time thing, also opens the for other wrappers ('extends', Harmony etc)