joevallender
joevallender

Reputation: 4293

ember.js and require.js

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

Upvotes: 3

Views: 7551

Answers (4)

Wojciech Bednarski
Wojciech Bednarski

Reputation: 6373

As @mpm wrote, there is nothing special about Ember.js + RequireJS or other no-AMD framework + RequireJS.

Good starting point is RequireJS documentation and Ember.js + RequireJS TodoMVC project example:

Upvotes: 1

mpm
mpm

Reputation: 20155

There is nothing that makes emberjs / requirejs relationship special , they are orthogonal. Does Ember solves dependencies between script files ? no , Is requirejs a MVC framework ? no , so what is the problem ? The use of requirejs with emberjs is no different from the use of requirejs with any library that doesnt provide AMD. So nothing special here. You want AMD ? use requirejs to define your own modules and resolve dependancies between them , that's the point.

The only question is , do you have a problem to solve or not ?

Upvotes: 2

Fernando Gm
Fernando Gm

Reputation: 1191

If you still want to use EmberJS and RequireJS,

I've just uploaded to github a starter-kit for EmberJS+RequireJS, You could check it https://github.com/fernandogmar/Emberjs-RequireJS

It's my particular suggestion for big enough projects...

Any good suggestions will be highly appreciated. Have Fun!

Upvotes: 3

abaelter
abaelter

Reputation: 917

Haven't made up my own opinion yet but this is what Ember.js developer Tom Dale has to say on the matter.

http://tomdale.net/2012/01/amd-is-not-the-answer/

Upvotes: 5

Related Questions