给出以下代码
function triggerAction() {
const asyncAction$ = of("value1");
asyncAction$
.clientLogin()
.pipe(
first(),
tap(val => console.log(`Test: ${val}`)),
)
.subscribe();
}
Run Code Online (Sandbox Code Playgroud)
我需要取消订阅吗?以前,当首先使用已修补的运算符时,它们会在第一个事件发出后取消订阅,但是文档中没有立即清楚管道运算符等效运算符是否相同.
https://www.learnrxjs.io/operators/filtering/first.html https://rxjs-dev.firebaseapp.com/api/operators/first
mar*_*tin 13
RxJS 5和RxJS 6版本的first工作方式相同,因此您无需取消订阅,因为它完成了链并因此触发了处理处理程序.
如果你想确定你可以添加complete回调给你tap,看看它是否被调用(你也可以添加它subscribe):
asyncAction$
.clientLogin()
.pipe(
first(),
tap({
next: val => console.log(`Test: ${val}`),
complete: () => console.log(`Complete`),
}),
)
.subscribe();
Run Code Online (Sandbox Code Playgroud)