julx
julx

Reputation: 9091

Backbone.js and its API confusion

I've recently started using Backbone.js. I like the architecture, in terms of features it's almost exactly what I need...

... However I found the following caveats:

I would like to know: what are the best practices regarding the mentioned situations? What do you do to make the framework more consistent - any monkey patching? Am I doing anything wrong / against the convention?

I'd be grateful for any good real world examples. I did find this: http://documentcloud.github.com/backbone/docs/todos.html and http://liquidmedia.ca/blog/2011/01/backbone-js-part-1/ and those don't address any of the mentioned problems. In fact they just present the simplest ideas and absolutely no border cases, so anything more complicated could be useful.

EDIT:

Ok, and there is one more fundamental think I don't understand:

EDIT(2):

Well, I found this: http://maccman.github.com/spine/. It looks like Backbone.js 2.0, shares a similar name too :). Haven't tested it yet, which might be a bit of a show stopper, as the library is very recent. However from the docs side of things it looks very promissing. It gets rid of most of the problems that I found, it simplifies the API, it even gets rid of the dependency on underscore.js which for a library is a good thing. I'll post my further findings here.

Upvotes: 15

Views: 2579

Answers (2)

julx
julx

Reputation: 9091

Ok, I think I can say it quite confidently now: Backbone is dead, long live Spine.

Spine isn't exactly a fork of Backbone. It is however very similar and clearly inspired by some of the design decisions. It could be said that the author tried to retain as much as it was possible the original backbone API, getting rid of everything unnecessary or illogical. I find it also easier to extend. The list of changes includes among other things:

  • Getting rid of the dreaded Collections. "class methods" are used instead,
  • Getting most out of js prototypical nature (i.e. no get/set is needed). Attributes are accessed directly. An explicit call to save() is required in order to trigger an event.
  • Views and Controllers are now merged into new type of Controllers together whose purpose is to respond to DOM events and bind to model events.
  • The name :)

I find those design decisions coherent and sensible.

Upvotes: 10

Lyn Headley
Lyn Headley

Reputation: 11588

The reason there is no 'set' for Collections is because Collections are not arrays, they are sets, which are potentially ordered. The only supported way to place an element at a particular position is to add it to the collection and then sort the collection.

Upvotes: 0

Related Questions