jupiterjs/canjs — pull request #91 by makebbekus (2012-08-27 06:05:31+00:00)
Title: can.Model.List attr() behaves unexpectedly when passed an array of data that doesn't match the order of the list

When you pass an array value to the attr() method of can.Observe.List, it iterates by position over both lists and updates each item in the list with the data from the item in the same position in the Array.

For a can.Model.List it seems like rather than going by position, attr() should look in the list and find the object based on it's "id" field and then update it if it exists. The tests in model/list/list_test.js illustrate the issue and fail without the provided code changes.

The real world scenario for this is that we have a list of model objects (in our case Tasks) and the response from the server doesn't always match the order of our data. This is because new tasks could have been added or removed to the list or a user has re-ordered the list.