

Backbone 0.9.0 released - singingwolfboy
http://backbonejs.org/#changelog

======
jashkenas
Hey folks -- this should be considered a release candidate for a 1.0. We're
currently running 0.9.0 on DocumentCloud.org; let me know if you have any
trouble upgrading. There's a few things to watch out for, listed here:

<http://backbonejs.org/#upgrading>

Really, in the little over a year since the initial Backbone.js code drop,
it's been incredible to see how many amazing apps have been built with it, a
sentiment expressed concisely on Twitter this morning:

[https://twitter.com/#!/donnierayjones/status/164012817584881...](https://twitter.com/#!/donnierayjones/status/164012817584881664)

Cheers!

~~~
oomkiller
This is probably a little bit late for this release, but have you ever
considered allowing arrays or strings with spaces on the value side of the
events hash? This would allow you to define different functions to call in
order when an event is fired, instead of just a single function that has to
call them itself. I've run into a few situations where this would be useful,
and seems like a very small change. Should I send a pull request?

~~~
DougWebb
I'm not familiar with the Backbone code or config. However, it sounds like you
are setting an argument by specifying a function name in a string. If you want
to specify multiple functions, then instead of specifying them in a string I'd
say Backbone should accept either a string or a function as the argument
value. That would let you define your event handler in-place, and you could
define one that just calls a series of other functions.

~~~
jashkenas
No, that's not quite it. It's simply that you're now allowed to bind and
trigger multiple _event names_ in a single call, as in jQuery. For example:

    
    
        book.on("change:title change:author", function() {
          ...
        });

------
koko775
I'm trying to learn Backbone, I really am. But there's so many tutorials
suggesting everything that I don't have a clue how I should structure a
project and what to think about as a codebase grows.

Granted, I'm fairly new to Javascript, but - no offense meant - I can't get
excited about node.js. Backbone is the first thing about Javascript that
really makes me want to write it. And I know enough to know what I lack is
primarily practical experience, but every step I take with Backbone feels like
a misstep, because it seems like there's no one right answer by design, so I'm
paralyzed.

What to do?

~~~
fiznool
I was in a similar position to you a little while back. I found the annotated
source of the TODO app on DocumentCloud a good start. I then found it was
worth spending the money on Recipes with Backbone by Nick Gauthier & Chris
Strom.

[http://documentcloud.github.com/backbone/examples/todos/inde...](http://documentcloud.github.com/backbone/examples/todos/index.html)
<http://documentcloud.github.com/backbone/docs/todos.html>
<http://recipeswithbackbone.com/>

That being said, I've always found the best way to learn, is to do. Come up
with an idea for an app and build it using Backbone, with the help from the
resources above. You'll learn a lot.

~~~
koko775
Thanks, I'll take a look at it. I'm always willing to invest cash in myself to
buy good educational materials.

------
davej
Changelog

* Creating and destroying models with create and destroy are now optimistic by default. Pass {wait: true} as an option if you'd like them to wait for a successful server response to proceed.

* Two new properties on views: $el — a cached jQuery (or Zepto) reference to the view's element, and setElement, which should be used instead of manually setting a view's el. It will both set view.el and view.$el correctly, as well as re-delegating events on the new DOM element.

* When you don't know the key in advance, you may now call model.set(key, value) as well as save.

* Multiple models with the same id are no longer allowed in a single collection.

* Added a "sync" event, which triggers whenever a model's state has been successfully synced with the server (create, save, destroy).

* bind and unbind have been renamed to on and off for clarity, following jQuery's lead. The old names are also still supported.

* A Backbone collection's comparator function may now behave either like a sortBy (pass a function that takes a single argument), or like a sort (pass a comparator function that expects two arguments). The comparator function is also now bound by default to the collection — so you can refer to this within it.

* A view's events hash may now also contain direct function values as well as the string names of existing view methods.

* Added shuffle and initial to collections, proxied from Underscore.

* Model#urlRoot may now be defined as a function as well as a value.

* View#attributes may now be defined as a function as well as a value.

* Calling fetch on a collection will now cause all fetched JSON to be run through the collection's model's parse function, if one is defined.

* You may now tell a router to navigate(fragment, {replace: true}), which will either use history.replaceState or location.hash.replace, in order to change the URL without adding a history entry.

* Within a collection's add and remove events, the index of the model being added or removed is now available as options.index.

* Added an undelegateEvents to views, allowing you to manually remove all configured event delegations.

* Although you shouldn't be writing your routes with them in any case — leading slashes (/) are now stripped from routes.

------
jdminhbg
Nodding my head the whole way through the changelog -- I just manually
implemented undelegateEvents today. Looking forward to trying this out.

------
radagaisus
The sync addition is great, you can patch backbone to trigger a 'loading'
event to accommodate it: <https://gist.github.com/1500028>

My biggest point of pain with backbone is the models, in one project I had to
add lazy loading (pagination) and in another a sparse array implementation
which was a lot of hassle.

The other point is boilerplate - there's a lot of it. projects like backbone-
forms (<https://github.com/powmedia/backbone-forms>) try to fix it, but it's
still a problem.

~~~
jashkenas
If you don't mind elaborating more, and/or opening tickets, I'm sure there are
plenty of folks who'd be glad to help with the pain points.

Pagination shouldn't be too big of a deal -- that's precisely the sort of
thing that Collections can make easy ... ditto for modeling a sparse array
(although I'm fuzzy on why you'd need that -- if it's for performance only,
you should be using something more low level)...

As for boilerplate, I'm not sure what Backbone-forms has to do with it -- if
you're suggesting that Backbone should include UI widgets for auto-generating
forms ... I think that's _very_ far away from the role that Backbone is
supposed to serve.

~~~
radagaisus
To clarify: backbone is so great and widely adopted because it is almost
perfectly agnostic and easy to plug into other libraries. But, it feels like
Connect, not Express. There's still boilerplate in my code to crush.

I don't like feature request issues, once we are done with the current project
we'll send a couple of pull requests.

~~~
jashkenas
Looking forward to 'em.

------
ender7
The 'sync' addition is neat.

Is there any way in Backbone to get a list of all of a model's properties that
have been changed since the last sync? model.changedAttributes() only works
for the most recent change (and only inside of a 'change' event listener).

The reason I ask: I'm working on a system that only syncs model attributes
that have changed - it doesn't send the entire JSON of every changed model. To
do that it currently has to keep track of which attributes are 'dirty' or not
for each model.

~~~
jashkenas
I'm having a hard time seeing how "changedAttributes" isn't exactly what
you're describing -- the difference in attributes since the last time the
model was changed/synced.

That said, if you need something fancier, and can't you simply listen on
"change" events, and stash the last set of changed attributes where you can
look them up later?

~~~
ender7
Yeah, that's what I'm doing now. Sorry, I realize I was being silly; the
reason I needed this behavior is that I've overridden Backbone.sync to sync to
the server in batches (every six seconds), rather than send off a new sync
every time there's a change. I'd forgotten that I was doing something
nonstandard there...

------
phzbOx
"A view's events hash may now also contain direct function values as well as
the string names of existing view methods."

Nice! I've always been wondering why I couldn't pass a function there.

Thanks

------
renownedmedia
Man, I must have been doing something wrong with my models. I'm getting this
error in my console when normally it triggers my validation errors:

"Uncaught Error: Can't create an invalid model"

~~~
jashkenas
Validation has gotten an overhaul -- I'm afraid it'll no longer allow you to
create a model in an initially invalid state.

If you'd like to keep the same flow, first create an empty model, then `.set`
the attributes on it.

~~~
terryroe
I don't understand. If you create an empty model and you have a validate
function, the validate function still runs and you aren't able to create the
model.

Also, I don't fully understand the workflow for a "new" form. If the form
needs to handle both a "new" model with no attributes (invalid state) and an
existing model for update, how does one go about that? (I'm currently using a
mock for the new state.)

I realize this are two different issues, but they are somewhat related to the
problem of creating a model with no attributes, which is a model in an
initially invalid state.

------
jhuckestein
Uh oh, and I thought it was clever to monkeypatch a function this.$el() into
views that returns the cached jquery/zepto element and is mindful of changes
to this.el ;)

