Hacker News new | ask | show | jobs
by catshirt 4841 days ago
>> How does everything fit together?

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.

2 comments

I wasn't commenting on Backbone itself, I was commenting on getting started with Backbone. I've held 15+ workshops and presentations on Backbone and helped a lot of people getting started. These are the issues I have most often heard from them.
my point is that these questions seem either misdirected or simply answered. that is to say, it's not a framework. it's a set of classes. how you handle templates, how these classes fit together, etc is hardly a function of 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.

Catshirt, I actually would love to get feedback on this comment:

>> 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 :)

router functions i think are sufficient. if size is a problem, multiple routers could help. different routers could also generalize instantiation for certain types of pages. if it gets more specific than that, i put it into the page view logic like you suggested. does this sound reasonable?

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.