【发布时间】:2019-03-11 22:15:27
【问题描述】:
我想使用“takeUntil”运算符以声明式方式取消订阅。但这基本上是行不通的。反正我可以看到控制台输出。
const unsubscribe = new Subject();
function printFoo() {
of('foo')
.pipe(takeUntil(unsubscribe))
.subscribe(console.log) // Why I can see 'foo' in the console?
}
function onDestroy() {
unsubscribe.next();
unsubscribe.complete();
}
onDestroy()
setTimeout(() => printFoo(), 200)
斯塔克闪电战:
https://stackblitz.com/edit/rxjs-svfkxg?file=index.ts
P.S.我预计即使unsubscribe.next() 也足以取消订阅,但即使使用unsubscribe.complete() 也不起作用。
【问题讨论】:
标签: javascript rxjs reactive-programming