.select上的rxjs / ngrx组播

时间:2018-11-12 12:46:16

标签: angular rxjs ngrx multicast ngrx-store

echo $out_1;中,我应该始终多播@Component吗?

例如

.select(myCustomSelector)

否则,每次我执行this.store.select(myCustomSelector).pipe(share()); 时,它将创建一个新的订阅。还是因为选择器被记忆而已?

我想知道什么是好的做法。

2 个答案:

答案 0 :(得分:2)

不,您不应该将share().select()一起使用

但这取决于您使用的商店实现方式。

在ngrx,ngxs和秋田县,商店由一个对象支持,因此从select返回的可观察对象不会触发任何副作用。

然后通过reducer更新存储,然后所有选择都将获得一个新值,但是由于它们都在使用单个对象(状态),因此不会出现性能问题。

答案 1 :(得分:0)

为什么不只在模板的顶层做一个async然后重用值?

<ng-container *ngIf="myItems$ | async as myItems">
<div *ngFor="let item of myItems">....</div>
<div *ngFor="let item of myItems">....</div>
<div *ngFor="let item of myItems">....</div>
</ng-container>