Background:
I play with javascript-in-browsers a lot in my free time (when I can find it), nevertheless new to AMD modules. I get paid to write rails. We have some tangled javascript at work (stop me if you've heard this one ;-) and I'm hoping to gradually introduce AMD modules to get better engineering discipline around our front end.
Goal:
My slightly longer-term ambition is to use wire because ... dependency injection.
Question:
Here's what I think I understand about AMD (ignoring Rails asset pipeline for the moment). Can you confirm or deny this stuff -- and maybe tell me what I might not know I need to know?
define(['foo', 'bar'],/* my awsome stuff happens here */);
With this module definition, if I were in node.js, I could do this:
namesMatter = require('my-awesomeness');
And with curl in the browser I could do something similar, provided I get the paths right in my configuration:
namesMatter = curl('my-awesomeness');
The important part being that 'my-awesomeness' is a name that's comming from the file system in the case of node and from the basename of the url in the case of curl.js (caveat that curl.js offers lots-o-configuration options for naming and paths and such).
By contrast this definition:
define('hardCodedName', ['foo', 'bar'], /* still awesome */);
fixes the name of the module to 'hardCodedName' instead of using the filename or url. If so, then my other modules could use that name in their definitions like so:
define('soCool', ['hardCodedName'], /* let the magic begin */);
If I do in fact understand that stuff correctly, then I think this second way of defining modules will play more nicely with Rails asset pipeline. In effect, I'll have a bunch of AMD modules with their names declared inside the parens of their defines. It'll be my job to control the order in which the files are concatinated so that dependencies are defined before modules which depend upon them.
But I think it also means I'll have some work to do in local forks of curl, wire, when and such to hard code their names. I can't tell yet if that would be more or less work than getting requirejs-rails working in our app and then connecting those dots to cujo.
Have I got this right? Are there any waterfalls downstream from here that I need to know about?
Many thanks.
-Eric