Let's say I am retrieving a list of player models and displaying them in a table format. Using the awesome-ness of live binding, if any attributes of a player change, that attribute will automatically be updated on the screen. Way cool stuff!
But how does it work if want to do the following:
Every N minutes I am going to go back to the server and ask for an updated list of players. When this list comes back, while it will contain most of the same player models (maybe exactly the same), they will be new instances of those models. Should I just re-render the entire view so I don't have to deal with the additions/deletions of models or is there a way for CanJS to know that this model I just got is the same as one already being displayed. Or even better, does live binding work with lists of models?
CanJS keeps a global Model store, so that there will always be only one instance of a Model with the same ID. So ideally reloading it should just update the view right away. I am not entirely sure if the converter in can.Model.prototype.model uses .attr() to update the attributes of an existing instance though, you might have to try that out. The list helper should take care of live binding the list but you will get back a different list instance so you might have to render it again anyway.
Nope, model store is in can/model and is always turned on. When part of your app binds to an instance it will be added to the store and when nothing is listening to an instance anymore, it will be removed.
I would refrain from accessing the store directly and instead use findOne, findAll and Model.Lists
That's the spot where the instance in the store should be updated, but you don't need to iterate over each attribute. attr() can take an object of key value pairs so you could update the instance like: