After experiencing some in-browser sluggishness, I'm trying to optimize change detection in my Angularfire-powered app. I read this SO answer and tried to model my list code similarly.
my container class:
<section *ngIf="inclusions$ | async as standardList">
<bl-list-item *ngFor="let standard of standardList;
trackBy: identify" [inclusion]="standard">
</bl-list-item>
</section>
NOTE: inclusions$ is an Oberservable<any[]> from Angularfire's Firestore.
trackBy function:
identify(index, item) {
return item.id;
}
presentational component:
@Component({
selector: 'bl-list-item',
...
changeDetection: ChangeDetectionStrategy.OnPush
})
The problem: ngOnChanges
is invoked for all instances of bl-list-item
, whenever the data for a single associated doc gets updated in Firestore. For example, if I make an edit to an Item-Doc
in the Firestore web console, all bl-list-item
instances fire ngOnChanges
, not just the item affected by the changes.
How do I correctly configure the list-item component so that ngOnChanges
only fires in affected items?