fix(devtools): do not refresh the ui unless there are updates

This commit is contained in:
mgechev 2020-03-16 16:23:10 -07:00 committed by AleksanderBodurri
parent 0b991bdc0f
commit 2a1f6e9464
2 changed files with 14 additions and 11 deletions

View file

@ -84,9 +84,9 @@ export class ComponentDataSource extends DataSource<FlatNode> {
return this._nodeToFlat.get(indexedNode);
}
update(forest: DevToolsNode[]): FlatNode[] {
update(forest: DevToolsNode[]): { newItems: FlatNode[]; movedItems: FlatNode[]; removedItems: FlatNode[] } {
if (!forest) {
return;
return { newItems: [], movedItems: [], removedItems: [] };
}
const indexedForest = indexForest(forest);
@ -101,7 +101,7 @@ export class ComponentDataSource extends DataSource<FlatNode> {
movedItems.forEach(i => this._nodeToFlat.set(i.original, i));
newItems.forEach(i => (i.newItem = true));
return newItems;
return { newItems, movedItems, removedItems };
}
connect(collectionViewer: CollectionViewer): Observable<FlatNode[]> {

View file

@ -25,9 +25,9 @@ import { arrayEquals } from 'shared-utils';
})
export class DirectiveForestComponent {
@Input() set forest(forest: DevToolsNode[]) {
this._updateForest(forest);
if (this.currentSelectedElement) {
const result = this._updateForest(forest);
const changed = result.movedItems.length || result.newItems.length || result.removedItems.length;
if (this.currentSelectedElement && changed) {
this._reselectNodeOnUpdate();
}
}
@ -103,18 +103,21 @@ export class DirectiveForestComponent {
}
}
private _updateForest(forest: DevToolsNode[]): void {
const newItems = this.dataSource.update(forest);
private _updateForest(
forest: DevToolsNode[]
): { newItems: FlatNode[]; movedItems: FlatNode[]; removedItems: FlatNode[] } {
const result = this.dataSource.update(forest);
if (!this._initialized && forest && forest.length) {
this.treeControl.expandAll();
this._initialized = true;
newItems.forEach(item => (item.newItem = false));
result.newItems.forEach(item => (item.newItem = false));
}
if (newItems && newItems.length) {
newItems.forEach(item => {
if (result.newItems && result.newItems.length) {
result.newItems.forEach(item => {
this.treeControl.expand(item);
});
}
return result;
}
populateParents(position: ElementPosition): void {