Performans ve “açısal yol” için daha iyi olan nedir: görünümde çok sayıda asenkronizasyon borusu var mı yoksa Bileşen abonelikten çıkma ile bir abone mi var?Köşeli 2: birçok Async borusu bir aboneye karşı
Örnek:
@Component({
template: `<div> {{ post.title }} {{ post.author.name }} {{ post.category.name }} </div>`
...
})
class AppComponent {
public post: Post;
public postSubscription;
ngOnInit() {
postSubscription = someObservable.subscribe((post) => {
this.post = post;
})
}
ngOnDestroy() {
postSubscription.unsubscribe();
}
}
veya açısal değişiklikler hakkında haberdar olur çünkü | async
boru daha etkilidir kullanarak
@Component({
template: `<div> {{ postTitle | async }} {{ postAuthorName | async }} {{ postCategoryName | async }} </div>`
...
})
class AppComponent {
public postTitle: Observable<string>;
public postAuthorName: Observable<string>;
public postCategoryName: Observable<string>;
ngOnInit() {
this.postTitle = someObservable.pluck('title');
this.postAuthorName = someObservable.pluck('author', 'name');
this.postCategoryName = someObservable.pluck('category', 'name');
}
}
Ancak "changeDetection" işlevini "ChangeDetectionStrategy.OnPush" olarak değiştirirseniz ve subscribe bloğunda "changeDetector.markForCheck()' işlevini kullanırsam? – dakolech
O zaman muhtemelen async borusunu kullanmakla aynı şey. –