I stumbled across Recipes With Backbone book by chance from a blog post by one of the authors, where he was discussing how to implement default routes. I was a bit hesitant at first when I couldn’t find many reviews of it, but ‘advanced Backbone’ is a pretty new subject area (even to find on blogs) and it was cheap so I bought a copy. I am glad to say I was very satisfied with my purchase.
The book has 152 pages, and it took me a day to read on my Kindle. It covers:
- Writing Client Side Apps (Without Backbone)
- Writing Backbone Applications
- Organizing with Require.js
- View Templates with Underscore.js
- Instantiated View
- Collection View (Excerpt)
- View Signature
- Fill-In Rendering
- Actions and Animations
- Reduced Models and Collections
- Non-REST Models
- Changes Feed (Excerpt)
- Pagination and Search
- Constructor Route
- Router Redirection
- Evented Routers
- Object References in Backbone
- Custom Events
- Testing with Jasmine
The book is based around a hypothetical online calendar application, analogous to Google Calendar. I use GCal a lot so it was nice to have familiar examples — some books use made-up applications that are unfamiliar or too vague (even a blog or a todo list could be designed in many different ways). But when examples are based based off a specific real-world application like GCal or Twitter then you already know how it’s supposed to behave and it simply becomes a matter of mapping that behaviour to the code examples on the page.
The book is structured as a series of enhancements to the calendar — starting with a plain jQuery $.getJSON() on a server-generated HTML page, just like we used to write in 2008. This was a good familiar starting point for me, before leaping into a basic Backbone structure and then refactoring it and adding more advanced behaviour.
The twenty chapters are each presented in a problem: solution format. They are very brief but I really liked this — they are clear, succinct, get straight to the point, and are very readable. Code is explained in 3-4 line chunks at a time, which fit well on my Kindle (which has a small screen and no colors). Overall I thought it was very good value for time spent reading.
For me, the book was valuable because:
- It corrected some things I thought I already knew 🙂 like $(el) injection
- It showed patterns for dealing with things like view deactivation and dangling event references (as a WPF developer this stuff gives me nightmares)
- It showed how simply and elegantly difficult things like paging could be implemented
- It suggested some neat things I hadn’t even thought about yet e.g. constructor routing
The book also includes a chapter on Require.js, which it presents early on as a foundation — chapter four — right after namespacing. I’m a fan of require.js and have no doubt it will soon become a standard requirement for any serious JS development in future. But right now it’s not widely supported and — in my experience — can cause a lot more problems than it solves. Unless you’re totally comfortable accepting the fact you’ll probably have to hack a lot of third party jQuery plugins just to make them work, I would not recommend require.js to beginners until the rest of the community catches up.
Regardless, Recipes With Backbone is still the single best text I’ve read on Backbone (aside from the Backbone docs themselves), and I’m looking forward to seeing what else these guys write. I would definitely recommend it to anyone wanting to take their Backbone skills to the next level. Go check it out and read the sample chapters here: http://recipeswithbackbone.com