Live data from Hacker News

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

documentcloud.github.com

31–40 of 62 posts

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

#31

I'm a little confused about what the best-case/ideal scenario is for this. As an example, I am currently working on a project that has a basic profile page. So on the server side, I have my nice OO representation of a Profile object, complete with properly defined public and private variables, a slew of functions, and a save() function that validates saves the data to the database. When I display that page to the cli…

Backbone is intended for JavaScript-driven web applications. If you're doing most of your logic and HTML rendering on the server-side, then it's not appropriate for you.

However, if you have an application with a lot of JavaScript interactivity, or a single-page application where the entire interface is driven from JavaScript (this is the case for us), then it helps to structure your client-side code with a little more oomph than just jQuery provides.

Taken to the extreme, in our case, the DocumentCloud workspace is effectively an empty body tag, and all of the HTML rendering and interesting logic happens in JavaScript models and views -- you never have to refresh the page. The server-side Rails code becomes smaller and less complicated, essentially delegated to performing validations and authentication and serving JSON to the client. Think GMail, or New Twitter, or 280 Slides...

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

#36
post #28

So if we were designing the Twitter front page with Backbone, we would have models like TrendingTopics, WhatYouDoing, NewMsgs and some more. They would be updating against the server using JSON, and calling some render code so they redraw themselves when there is new data. If we didn't have Backbone, we would probably call a main JSON sync function repeatedly, and iterate on this new data updating the different parts…

A more apt comparison is the "new twitter" homepage. If you load it and keep an eye on your Ajax requests, you'll see something like this: http://cl.ly/b043f31cd91dfdac8918 There, Recommendations, Friends, Followers, and Memberships are the models, and render off the contents of that JSON. Of course, Twitter should really be bootstrapping all of those bits of JSON into the initial page load, instead of firing off six…

Thanks, and yep I meant newtwitter. (How long until we can call it twitter? :)

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

#37
post #32

Looks great - imagine that it would be a perfect companion to something like sammy.js

Yes, they could work together quite well.

However (and this is another conversation altogether), I don't think that you really want to structure your client-side application around faux-routes. Maintaining browser history with "hashchange" is important, but hardly the central aspect of a JS app. Usually you want to reserve history changes for special states that deserve to be bookmarked, not for every single action performed.

For the record, this is the little module that we use to record and listen for "hashchange" events:

http://gist.github.com/624773

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

#38

I'm a little confused about what the best-case/ideal scenario is for this. As an example, I am currently working on a project that has a basic profile page. So on the server side, I have my nice OO representation of a Profile object, complete with properly defined public and private variables, a slew of functions, and a save() function that validates saves the data to the database. When I display that page to the cli…

Backbone is intended for JavaScript-driven web applications. If you're doing most of your logic and HTML rendering on the server-side, then it's not appropriate for you. However, if you have an application with a lot of JavaScript interactivity, or a single-page application where the entire interface is driven from JavaScript (this is the case for us), then it helps to structure your client-side code with a little mo…

Okay, that makes sense. Thanks for the reply.

So basically this is for those folks who are making real "web applications" -- meaning applications where a lot is happening on the client side, typically more of a "single URL/page", with dialog boxes and whatnot as opposed to a bunch of pages in the more traditional "web site" sense.

I have often considered trying out Cappuccino, but for some reason none of the websites I build end up being "web applications" in this sense. But I can't help but wonder if that's because they aren't, or if it's because I'm not thinking about them the right way.

It's outside the scope of this topic, but I can't help but ask: "How do you know when a website becomes a web application"? Is it the scope of the problem (trying to do "one thing", e.g. edit a photo, vs. presenting an entire web site full of information?) Or is it truly just a preference thing? I can only think that as projects like Node.js gain prominence, the lines will continue to be blurred...

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

#39

Earlier quoted context omitted.

Backbone is intended for JavaScript-driven web applications. If you're doing most of your logic and HTML rendering on the server-side, then it's not appropriate for you. However, if you have an application with a lot of JavaScript interactivity, or a single-page application where the entire interface is driven from JavaScript (this is the case for us), then it helps to structure your client-side code with a little mo…

Okay, that makes sense. Thanks for the reply. So basically this is for those folks who are making real "web applications" -- meaning applications where a lot is happening on the client side, typically more of a "single URL/page", with dialog boxes and whatnot as opposed to a bunch of pages in the more traditional "web site" sense. I have often considered trying out Cappuccino, but for some reason none of the websites…

The line is as blurry as you'd like to make it. A great example of this is Google Instant. Old Google.com was a web page -- and Google Instant is now a web application, the page doesn't refresh, and sends down JSON data which is rendered into your search results by JavaScript...

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

#40

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…

I'm a JavaScript newbie. I'm just curious as to how your code (as shown in dpaste.de/pKOi) is better than Douglas Crrockford's module pattern? Please enlighten me,thanks for help.
Post reply on HN