Quantcast
Viewing all articles
Browse latest Browse all 3491

Re : can.Model.List: Should it automatically update when model created/updated

Hi,
In canjs 1.1, for new models I think you need to push into the list. This makes sense, for example, say it is a list of TODO items that are "Done", CanJS wouldn't automatically "know" if your newly created model should go in that list or not. It's up to you to add it to the list, or to call findAll again (or maybe to bind to the create event and check if the item.Status == "Done")

For updates, it should definitel update items in the list.

In the background, instances of models are stored in a static hash object in [Model].store. So..

//when you do a findAll
Document.findAll()

//the results get stored in 
Document.store; // {334: {title: 123}, 212: {title: 444}}

//This is because CanJS tries to keep only one version of each model instance (to have one version of the truth)
// If you subsequently do this:
Document.findOne({id: 334}) // canJS will combine this result with Document.store[334];

// So when you update a model instance, the instance in the list should be updated too, because it should be the same instance...
model.attr("title", "new name"); 


HTH,
Bryon


Viewing all articles
Browse latest Browse all 3491

Trending Articles