Skip to content

Instantly share code, notes, and snippets.

@daybrush
Last active August 2, 2019 05:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daybrush/454501877be538d39af06eeb8c5c0f3f to your computer and use it in GitHub Desktop.
Save daybrush/454501877be538d39af06eeb8c5c0f3f to your computer and use it in GitHub Desktop.
function sync(result) {
const { maintained, removed, added, list } = result;
const prevItems = this.items;
const newItems = [];
maintained.forEach(([beforeIndex, afterIndex]) => {
newItems[afterIndex] = prevItems[beforeIndex];
});
added.forEach(i => {
newItems[i] = new Item(list[i]);
});
this.items = newItems;
this.recaculateItems();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment