Announcing Backbone.js: Models, Collections and Views in 2.4kb
21–30 of 62 posts
Re: Announcing Backbone.js: Models, Collections and Views in 2.4kb
#22I got a sneak preview of this yesterday. Having worked on a couple of large-ish JavaScript UI projects this is the kind of thing that people invent over and over again without ever distilling a minimal, extensible, and reusable set of functionality, it's either too application specific or heavily embedded in a larger framework (Cappuccino/SproutCore). MooTools+Backbone.js and/or jQuery+Backbone.js sounds like a kille…
Re: Announcing Backbone.js: Models, Collections and Views in 2.4kb
#23Edit: It looks like it's taken straight from the source (http://github.com/documentcloud/backbone/blob/master/backbon...) using Docco: http://jashkenas.github.com/docco/
Re: Announcing Backbone.js: Models, Collections and Views in 2.4kb
#24Key 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.
For saving, a single update often needs to be a single request, and the UI needs to know that the update has been applied successfully. If you need to do a bulk update, then use "set", not "save", and make a custom Ajax call for the bulk operation.
Finally, Backbone.sync is the lowest-common-denominator default REST request, which will work for many applications. You can and should override it if you have more specific needs -- using timeouts to aggregate many granular saves into a single HTTP request is a great idea for some applications...
Re: Announcing Backbone.js: Models, Collections and Views in 2.4kb
#25Re: Announcing Backbone.js: Models, Collections and Views in 2.4kb
#26Re: Announcing Backbone.js: Models, Collections and Views in 2.4kb
#27Wow 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…
Re: Announcing Backbone.js: Models, Collections and Views in 2.4kb
#28If 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 of the page "manually".
Is that it?
Re: Announcing Backbone.js: Models, Collections and Views in 2.4kb
#29As 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 client, I have a PHP view which takes the data from the model and then renders it. In the view, I do currently use jQote2 to do some basic client-side templating where appropriate (for example, displaying all of the friends of the profile's user).
Now, the Profile page features the ability to edit profile fields. There is jQuery involved here. Currently, I just have a function that is called when the "Save" button is clicked that gathers up all the various data from my input fields and whatnot, and sends that off as JSON to be saved on the PHP side of things.
Is this someplace where Backbone.js would make sense? Would I then have to have a representation of my model both in PHP and in Javascript? And my PHP view would contain several Javascript sub-views? And when I do save the model on the Javascript side of things, am I then just executing database queries on the PHP side, or am I re-loading the model, changing the attributes, and then using the PHP model's save() function?
I guess I'm just confused as to where this fits into the grand scheme of things. There's a part of me that certainly likes the idea of data binding and having smart re-rendering of parts of my pages based on when models change, but I'm just unclear on how this fits into my existing PHP MVC stuff.
Re: Announcing Backbone.js: Models, Collections and Views in 2.4kb
#30So 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…
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 requests immediately...