Hacker News new | ask | show | jobs
Backbone.js by example (javageneration.com)
74 points by emwa 5265 days ago
4 comments

I started looking at Backbone.js over the last few days.

I started with reading the documentation[1]. It is very well documented and contains a wealth of information.

Then I took a look at the Todo example[2] referenced in the documentation. It is also very well documented and puts together all the basics of the documentation into one clean example.

At this point, I started branching out into other tutorials. Everything I read basically reiterated the documentation and example above. This was good in terms of drilling the ideas into my head more solidly, but I could have stopped after the Todo example.

There was one notable tutorial though that was very different. Backbone provides a framework, but does not specify a structured way to store or load files. I believe this is on purpose. Backbone concentrates on the framework and gets out of your way. This leaves some head scratching though. This tutorial[3] combines Backbone.js with Require.js and provides an intriguing solution.

[1] http://documentcloud.github.com/backbone/ [2] http://documentcloud.github.com/backbone/docs/todos.html [3] http://backbonetutorials.com/organizing-backbone-using-modul...

Interesting to see Backbone being used to model non-crud single page apps. I had to build a SVG based editor before and looking at this example I can see how using Backbone would have made my life easier.
Thank you.

As a backend developer trying to embrace Backbone, I'm finding that there isn't a wealth of consistently good material to learn from. One tutorial will push everything to the view, and the next pushes everything to the router.

It's hard to determine exactly what the best practices are, and making up my own mind isn't necessarily that informed, as I'm just learning the framework.

I'm hoping for more and more documentation to appear as there are things that I simply can't figure out how to do and can't find a reference for anywhere. Every resource helps.

Best resources I've found on backbone are articles from Derick Bailey at LosTechies.com

http://lostechies.com/derickbailey/

Unfortunately, this site has gone dark for the day due to the SOPA protest. Will have to check this out once it comes back up.
I'm quite sorry to agree with you -- there are a bunch of no-so-helpful Backbone tutorials floating around out there.

That said, most of the questions that we field that take the form: "Should I be doing X like Y in Backbone?" ... the answer is usually: Sure, that will work fine. In fact, there's a whole section in the FAQ about it:

http://backbonejs.org/#FAQ-tim-toady

Is there something in particular you're trying to figure out how to do?

Complicated(?) template rendering. I have a template with varying sized elements, and a collection of images that I need to stuff into said template.

Not sure how to accomplish it, as I can't just iterate through the results as I need to put the right sized image into the right-sized grid (or scale it, which might be easier), but either way, I have four columns, some of which have either 1 or 2 rows, and each of the rows may be of different heights.

I know that there will always be seven elements in the template, and there are fixed heights that I can cheat with, but beyond that, I'm stumped.

Is the problem specific to rendering them with Backbone? If you always know the html/css solution, it's just a matter of picking one of the many js templating systems that works best. Of course, for very advanced manipulation, you can always just full back to writing a render method yourself and munging the nodes with jQuery.
Using a template library that allows arbitrary code will probably make this easier...

But it sounds like what you want to do is precompute all of the correct widths and heights for your elements, based on the image sizes. Then, when you go to render, you can simply look up the appropriate width, height, margin, padding for each cell.

Good example. I liked your way of binding model events to views - which is usually not the most elegant part of Backbone. Thanks!