Live data from Hacker News

Announcing Backbone.js: Models, Collections and Views in 2.4kb

documentcloud.github.com

11–20 of 62 posts

Re: Announcing Backbone.js: Models, Collections and Views in 2.4kb

#11
post #7

Sorry, I'm a little late to the party with respect to javascript. Could someone please explain to me what this means in english? Backbone supplies structure to JavaScript-heavy applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing application over a RESTful JSON interfa…

Yep -- let's dejargonize that for you: "key-value binding and custom events": When a model changes its state, other JavaScript objects can listen for that change and be notified. It's the usual inversion-of-control pattern, but especially crucial for models and views. A model has no business knowing about what views may or may not currently be present in the UI. Instead, the views listen to changes in the model, and…

Yes it does. Thank you for the explanation.

For anyone unclear about REST, try this: http://tomayko.com/writings/rest-to-my-wife

Re: Announcing Backbone.js: Models, Collections and Views in 2.4kb

#14
post #8

I'd be interested to know how this compares to js-model ( http://benpickles.github.com/js-model/ ). Anyone have any insight?

Yes. I recently discovered js-model while wrapping up the Backbone documentation. The two libraries are extremely similar, and share the same core idea, but with that said, here are some of the differences:

* js-model is explicitly inspired by Rails' ActiveRecord models, and a lot of these points fall out from that fact...

* In js-model, a collection and a model class (constructor function) are the same object. This is a big problem in client-side code -- you don't always want to have just a single collection of say, notes. That makes sense in a one-database-per-app, one-table-per-model world, but not so much in JavaScript.

* Backbone sets up the prototype chain so that you can continue to extend (subclass) your Models, Collections, and Views.

* Backbone includes a richer set of enumerable functions, based on Underscore.js, so you get native performance in browsers that support them natively.

* js-model's validation and errors API mimics Rails' Errors object, which may or may not be what you want.

* Backbone includes Views, and js-model sticks to models.

That's just a list of things off the top of my head. It's an amazing example of convergent evolution in code -- and I think it's much more widespread than this. In my experience, many folks who work on big JavaScript projects end up with an internal framework that bears an uncanny resemblance to Backbone.

Re: Announcing Backbone.js: Models, Collections and Views in 2.4kb

#15
post #8

I'd be interested to know how this compares to js-model ( http://benpickles.github.com/js-model/ ). Anyone have any insight?

Yes. I recently discovered js-model while wrapping up the Backbone documentation. The two libraries are extremely similar, and share the same core idea, but with that said, here are some of the differences: * js-model is explicitly inspired by Rails' ActiveRecord models, and a lot of these points fall out from that fact... * In js-model, a collection and a model class (constructor function) are the same object. This…

js-model has some nice support for serializing to local storage and so forth baked in, which I've found to be really handy.

Backbone looks like it forms a much more cohesive package though, which is nice.

Re: Announcing Backbone.js: Models, Collections and Views in 2.4kb

#16
post #3

Key point of Backbone.js: This is for designing web apps, not just a web page. When you have multiples of the anything on a page, it's time to move to separating out your views from your models, and Backbone.js is perfect for this sort of transformation. Even better if you start with Backbone.js. And Backbone.js is a minimal set of functionality to get this done. We use Backbone.js at DocumentCloud for our document w…

I'm concerned that the default approach to saving is making a request to the server. Defaults matter, and this default will lead people to ignore the 8 fallacies: http://en.wikipedia.org/wiki/Fallacies_of_Distributed_Comput...

N+1 across the internet will suck.

I assume it's early days, but please consider this issue. It's killed a bunch of otherwise interesting libraries.

Re: Announcing Backbone.js: Models, Collections and Views in 2.4kb

#17
post #8

I'd be interested to know how this compares to js-model ( http://benpickles.github.com/js-model/ ). Anyone have any insight?

Similar but it does seem to conflate the idea of a Model and a Collection. Also the instance changes API in js-model prefers an interface based around instance mutability instead of presenting the old and new value in a functional manner to the callback.

BackBone.js Models are also mutable. This is probably the only part of the design I would have handled differently at the cost of responsiveness in browsers with slower JS engines. In my experience it's too easy to accidentally corrupt the data which populates many UI components if you're passing mutable references around.

Re: Announcing Backbone.js: Models, Collections and Views in 2.4kb

#19
This looks great. I'm primarily a Flex developer and JavaScript for web apps has always scared the bejesus out of me as I felt I was back to the dark days of ActionScript 2. I still feel I'm faster with strong typing and a good IDE (I hardly type anymore it's all code completion) but micro frameworks like this are a huge step in the right direction.

Is there an IDE for serious JavaScript development? Right now for JS work I use TextMate with a bunch of custom tag triggers.

Re: Announcing Backbone.js: Models, Collections and Views in 2.4kb

#20
Wow I am incredibly impressed by this, great work to the DocumentCloud team! I can't wait to throw this into real-life use... it looks like everything I could ever want in a framework.

I too am a jQuery developer, but not your typical one. I tend to avoid slapping plugins together and write most of my own things from scratch, in my own pythonic classical style. I also tend to use the little jQuery helper methods and CSS selector tools purely as an interface to the DOM. The hard work is all done via classes, which drastically reduces the code that I write. I see other not-so-skilled jQuery script kiddies out there piecing together documents full of $('#blah') this and $('#bloo') that with little regard for chaining or simplifying things. I digress, as that is not the demographic for this wonderful library of code.

Here is an example of what kind of code I have been writing as of late: http://dpaste.de/pKOi/ -- as you can see, there is a small bit if boilerplate required and a 'var self = this' inside of each class method that is required. That's more for my own personal style actually, to help with preventing loss of 'this' scope down the road. Anyway... over time this code just sort of piles up and it would be nicer to 1) have a better way to define and organize it all, and 2) all of the great model/collection/validation stuff looks excellent! Evented programming is brilliant to, and the fact that a thousand pieces of code can all stay in sync thru events is just fantastic.

Post reply on HN