Let's say we have a collection:
var model = new Model([1,2,3,4,5])
and we render it with some javascript app framework like backbone, react, ember, angular, vue, etc. so the final result looks like this:
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
Now we add an item at the start:
model.unshift(0)
This would automaticallly redraw the collection somehow, so it would look like this:
<div>0</div>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
Now the part I'm curious about is how do these frameworks detect that it's only the <div>0</div>
that's new and prepend it to the collection view instead of thinking that it's a completely new collection (since all of the items indices have changed) and redraw the whole thing?
I am curious if there's some common logic they're using, and what is considered the "best practice" nowadays. Thank you!