Closed riebel closed 12 years ago
that sounds cool and I have no idea what it is. I'd be happy to include a "donated chapter" from a community member, but I feel in no way qualified to write about the subject.
Thanks for the feedback!
I may investigate this further in the days following the 1.0 release. My initial impressions are not favorable -- seems like a lot of ceremony and noise but that could just be the 1.0-induced sleep deprivation speaking :)
I am using RequireJS for a couple of month now and code structuring was never so easy. Keep your models, collections, views, router, template markup etc organized in seperate files and require them if you need them. If you are ready for deployment just run r.js with node.js or java and you recieve a single js file inlining all your js, template markup and translations. No need to litter your html file anymore.
A stripped down router.js example file:
define([
'backbone',
'../models/app',
'../views/appView'
], function(Backbone, App, AppView){
return Backbone.Router.extend({
initialize: function() {
var app = new App();
app.fetch();
},
routes: {
'': 'index'
},
'index': function() {
var view = new AppView({ model: app });
view.render();
}
});
});
More (somewhat outdated) examples here: http://backbonetutorials.com/organizing-backbone-using-modules/
OK. You might be onto something after all with this requirejs stuff :)
I really had a hard time wrapping my brain around it for some reason (even with your help), but now that I've done it, I have to admit that this could be pretty awesome.
My first exploration is described here: http://japhr.blogspot.com/2011/12/getting-started-with-backbonejs-and.html
Thanks for the pointers!
Done! Download the book from the original purchase email -- it's the new chapter 4 :)
Not really backbone specific, but it would definitely be useful to have some recipes and guides how to structure your app with RequireJS or any other AMD compatible script loader.