> which is what causes problems for a lot of people
> when getting to grips with it (myself included).
What exactly did you have a hard time coming to grips with? > which is what causes problems for a lot of people
> when getting to grips with it (myself included).
What exactly did you have a hard time coming to grips with?First of all, thanks for commenting on the thread! Also, I really hope it hasn't come across as though this post was "bandwagoning" on the "struggle with getting started with X.js week". The reason I LOVE Backbone is the fact is the fact that it's not opinionated on application architecture.
However, IMO no one (or not many) people build single page todo apps. People have real, multi-state and multi-screen apps that they're trying to build and I think that Backbone site/docs would really really helps people take their understanding of Backbone and architecture to the next level if an example was provided that went beyond the humble Todo app. DOM structure, Zombie events and View management (subviews, etc) are things that I feel are missing, not from Backbone itself, but that Backbone should/could provide as examples of using Backbone to deal with these real, use-case issues that arise.
I think this lack of documentation/examples acted as a catalyst for things like Marionette (hat tip Derick Bailey), but if patterns were outlined from the get-go on the Backbone site, people would be less inclined/feel the need to throw something like Marionette at it.
Hope this has come off as my humble opinion and not just "grumpy developer snark" - I love Backbone but I'd love to see it have an easier route for learning to build real world apps.
I guess the thing is that the current documentation works really well when you understand Backbone. Before you understand it, getting started is really difficult. That's why we see so many getting started guides all around — the problem of course being that most of them are barely just ok. Backbone should have a really, really good getting started guide, which (I think) should be more opinionated than Backbone itself — i.e. it shows one (really good) way of doing things (that works well when you scale up your application). Or at least link to one.
I've heard many say "look at the todo example", but I think that it's so far away from a real app that it's difficult to use as a starting point. It doesn't use ajax, it relies heavily on global state, it puts templates in the HTML, lots of global `$` stuff, no routing, etcetc. Ok-ish choices, but not a great example for those getting started. E.g. having templates in the DOM is ok when you have 5 views. When you have more it's problematic, especially for testing and for precompiling templates.
Backbone is great when you grok it, but it takes a lot of time to find your own patterns that works really well. (Marionette and Chaplin are awesome, but still, first when you have some basic understanding of Backbone itself)
initialize models and controllers, then pass that data to newly initialized views. at any scale, this hardly differs.
>> How should I handle templates?
backbone is template agnostic so the answer is "however you'd like". because I use r.js, my preference is loading the templates as separate text modules and defining them on my view. when our production script is build, the templates are inlined into the javascript through r.js.
your qualms with the todo example (no AJAX, global variables, strange template handling) are things that are not at all pertinent to Backbone and are solved by other patterns. point being, Backbone has it's own model/view pattern, but you can look at it in isolation. your other concerns are things solved by patterns with no pertinent relation to Backbone.
don't get me wrong. i've been there. i've had the same questions. but i think the answers i gave would have satisfied me when i was starting, had i had a mentor.
>> initialize models and controllers, then pass that data to newly initialized views. at any scale, this hardly differs.
Where do you find it makes the most sense to initialize models & controllers? I've done it in the router function but that feels really heavy and gets big.
Alternatively, since I use require.js I have used a view wrapper that initializes everything and then puts together the sub-views and models/collections as necessary. I like this approach because it feels more organized having it delegated out to my various view files.
Thanks in advance :)
aside, but to my original point, you could use any router and you'd still have this problem. these type questions are probably best not answered by Backbone.
edit: no need to downvote. i am open to suggestions or criticism.