backbone.obscura icon indicating copy to clipboard operation
backbone.obscura copied to clipboard

Unnecessary sorting on change between models with same comparators

Open ambischof opened this issue 8 years ago • 0 comments

Lets say we have a collection sorted on attribute 'name', and there are 4 entries with the name "Bob", if we change some other attribute, say 'age' on the second "Bob", it will remove that one and insert it at the beginning or the end of the "Bob"s, depending on directionality.

Cause: If we consider line https://github.com/jmorrell/backbone.obscura/blob/master/backbone.obscura.js#L641, the algorithm checks to see where it would be inserted, and if its current index is different from the new index. However this doesn't take into account whether the comparator of the model at the new index is different from the comparator of the model in question. If they are the same, they shouldn't be resorted.

This can cause very disruptive changes, especially when there's a small number of unique comparators compared to the size of the list.

ambischof avatar Jul 15 '16 15:07 ambischof