Hacker News new | comments | show | ask | jobs | submit login

Great job. Congrats!

Few questions though,

1. Would you consider adding computed properties to models and collections?

2. I have a bindModel and close methods to all my views so that close() unbinds all the methods in the views that were bound to the models/collections and it also unbinds the view events. Any reason why such a mechanism is not embedded out of the box in backbone? Or am I missing something?




1. I'm not a huge fan of treating computed properties as real data values -- because fundamentally they're not. One is part of the model's representation as a resource, and can be modified and saved back to the server, and the other is simply a computation based on the model. As peregrine suggests, I think they're much nicer as simple methods. For example:

https://github.com/documentcloud/documentcloud/blob/master/p... ... and so on.

2. Not all views display a single model -- some views show data from several, some views display an entire collection, and some views don't have any models attached. Additionally, if you tend to throw away your views at the same time you throw away your models (we tend to do this), you'll never have to unbind anything, as both are GC'd together.

It's only the case that if you tend to remove views but leave their models around to be rendered by other views later, then you need this sort of thing. And if that's the case for your app, then by all means, adding a `close()` function or the equivalent is a great idea.


1. Agreed, it force you to do things cleaner I guess.

2. The way I get around the problem is that bindModel takes (model, eventName, func, context) so having a view that represent different models isn't an issue in this case because it ends up being passed to bindModel.

example:

initialize: function () {

  this.bindModel(this.model.get('someCollection'), 'add', someFunc, this);
}

In the app I am working on, my models tend to live much longer than the views, and they usually get updates from the server.


Can you explain a bit more about #2? I'm not sure I understand fully what you mean.


1. Just add a method to a model or collection that does the computation. Javascript allows you to add methods to any object.

2. Good Question.


Right it does allow me to do that, but it doesn't get serialized and when a computed property depends on several attributes in the model, changing these attributes should also trigger the computed property change event.




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact

Search: