Thursday, October 14, 2010

Apps With Backbone

I've been working with a lot of JavaScript (single page) apps lately. I've found that the primary challenge of JS apps is keeping your data and UI sync'ed up.

There are those who say that attaching the data directly to the DOM is fine... But I'm leery of that. Some browsers (notably IE, of course) tend to leak memory when attaching extraneous data to the DOM. Plus, it just feels wrong. There's a reason "Separation of Concerns" (SoC) is a bit of a mantra.

Ideally you'd want to use something like Cocoa's KVC bindings for your UI. But the two main projects that have that as a goal, SproutCore and Cappuccino, are actually trying to implement the entire Cocoa stack on the web. Cappuccino even goes so far as to create a new language (sort of) to do so. Which is great, I guess, if you want to invest the time to learn their huge frameworks. (Don't get me started on their lack of decent docs.)

A new option appeared yesterday. DocumentCloud released an interesting so-called MVC framework named Backbone.js.

I should mention that it's not actually an MVC framework in the truest sense. It provides Models, Views, and Collections... MVC actually stands for Models, Views, and Controllers. For Controllers, I think Sammy.js is probably the best Controller framework you'll use.

Why is Backbone interesting? Because it's basically a small framework (~2Kb) that provides the core pieces of KVO bindings.

It's also built on top of jQuery and underscore.js. Bonus!

I'm definitely gonna be digging into Backbone and I'll write up my findings and some examples as I go along.

2 comments:

  1. Hey Matt,

    I've been working on something similar (although less documented). Might be useful to you:
    http://github.com/maccman/superapp
    http://github.com/maccman/supermodel-js

    ReplyDelete
  2. That looks interesting... I'll definitely check it out. Thanks!

    ReplyDelete