我很难理解RxJs。 5到6之间的突破性变化对我来说很难理解。
我有以下代码和以下问题。
我检查了更改日志以及修复重大更改的建议,但我无法理清我需要做什么。我理解它的方式,我的代码是旧的,不使用管道操作符,但这是我能够弄清楚的。
let polling = Observable.interval(2000)
.switchMap(() => this.http.get(this.videoStatusURL + this.taskID))
.subscribe(
(data) => {
if (data["state"] === "SUCCESS") {
//get final video here
console.log("polling succeeded");
this.downloadFinalVideo();
polling.unsubscribe();
}
},
error => this.handleError(error));
答案 0 :(得分:1)
请参阅pipe syntax in the migration doc部分,必须通过调用.pipe()
来调用运算符,因此您需要执行类似
import { interval } from 'rxjs';
import { switchMap } from 'rxjs/operators';
let polling = interval(2000)
.pipe(switchMap(() => this.http.get(this.videoStatusURL + this.taskID)))
.subscribe(
(data) => {
if (data["state"] === "SUCCESS") {
//get final video here
console.log("polling succeeded");
this.downloadFinalVideo();
polling.unsubscribe();
}
},
error => this.handleError(error));
或者,您可以安装rxjs-compat
,但这只是一个兼容层,您应该使用管道语法。