Skip to content

Commit

Permalink
perf(list): check before positioning element in dom
Browse files Browse the repository at this point in the history
  • Loading branch information
TremayneChrist committed Oct 25, 2021
1 parent c231f06 commit 244b44f
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions packages/elements/src/list/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,15 +591,14 @@ export class List<T extends DataItem = ItemData> extends ControlElement {
const currentChildren = Array.from(this.children);
const recyclableElements = this.calculateRecyclableElements(renderItems);
const renderChildren = renderItems.map((item) => this.createListItem(item, recyclableElements));
const deletions = currentChildren.filter(item => !renderChildren.includes(item));
deletions.forEach(item => this.removeChild(item));
renderChildren.forEach(item => {
const index = renderChildren.indexOf(item);
const deletions = currentChildren.filter(element => !renderChildren.includes(element));
deletions.forEach(element => this.removeChild(element));
renderChildren.forEach((element, index) => {
if (this.children.length === index) {
this.appendChild(item);
this.appendChild(element);
}
else {
this.insertBefore(item, this.children[index]);
else if (element !== this.children[index]) {
this.insertBefore(element, this.children[index]);
}
});
}
Expand Down

0 comments on commit 244b44f

Please sign in to comment.