在许多文章中,我发现 tap
操作符是执行副作用的一种好方法。我的问题是使用subscribe和tap执行副作用之间的区别。以下示例实际上正在执行相同的操作:
this.store$
.pipe(tap(x => {
this.store = x;
}));
this.store$
.subscribe(x => {
this.store = x;
});
这两种方法在性能方面有什么区别,或者使用其中一种方法有什么原因吗?