Skip to content

Instantly share code, notes, and snippets.

@daybrush
Last active July 14, 2019 17:54
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/451764fe58000647f4fe21bcd2ec78f0 to your computer and use it in GitHub Desktop.
Save daybrush/451764fe58000647f4fe21bcd2ec78f0 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(([beforeIdx, afterIdx]) => {
newItems[afterIndex] = prevItems[beforeIdx];
});
added.forEach(i => {
newItems[i] = new Item(list[i]);
});
this.items = newItems;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment