I've been trying to rework an as yet unfinished ember app of mine to use require.js
It's mainly for interest value and I started looking into it when I wanted to use require-text for my handlebar templates, for convenience. So I havent found myself looking into it for any sort of AMD related performance win or anything like that. But now I've started setting my module out by defining modules I am finding it easier to read and would like to stick with it.
There is a question on stack overflow where the asked has come back and posted their findings Ember.js and RequireJS but none of the other examples, like the example on todo MVC can be found on references on how to optimally structure and reference the files in more complex apps.
So anyway, my question is: What are the rules to follow to make correct use of require JS. What does it achieve (apart from access to AMD)? It's hard for me to get my head around it with a test project that doesnt really require it, but I'd like to learn the correct ember related principles so I can use it in future.
I've seen from example code that the idea may be to remove all references to the global namespaces from the modules. Is that correct? There arent enough examples around for me to spot a pattern.
At the moment a file at the top level of my structure might have some stuff like this in
<script>
define(['jquery',
'app/controllers/mailshotlist',
'app/controllers/sites',
'ember'],
function($, MailShotList, Sites) {
var App = Em.Application.create({
Views: Em.Namespace.create(),
Models: Em.Namespace.create(),
Controllers: Em.Namespace.create(),
init: function() {
this._super();
this.Controllers.set('Sites',Sites.create());
this.Controllers.set('MailShotList',MailShotList.create({
sitesControllerBinding: 'App.Controllers.Sites'
}));
}
});
return window.App = App;
});
</script>
So, trying to stitch together explicit app.x references in initialisation of the app. Since I guess if your modules are all referencing each other explicitly in the code then its not properly modular. I'm not at the stage where i want to reuse modules at the moment, but im assuming that is one of the goals
I'd like for this not to turn into a debate about whether AMD is worth it or not, my question is specifically about what rules need to be followed to get the most out of using ember with require js. Although if there are good specific reasons for not using ember with require then that would be interesting.
I think I've rambled a bit and am running the risk of getting this locked as 'non-productive' but If you can understand my question and what im trying to understand (or if im barking up the wrong tree entirely) then please post a reply