首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >从RxJs 5迁移到RxJs 6: switchMap和间隔中断

从RxJs 5迁移到RxJs 6: switchMap和间隔中断
EN

Stack Overflow用户
提问于 2018-05-30 04:10:46
回答 1查看 1.4K关注 0票数 2

我很难理解RxJ。5和6之间的突破性变化对我来说很难理解。

我有以下代码和以下问题。

Observable

  • .switchMap方法不再适用于
  1. .interval方法不再适用于.interval

我检查了changelog和修复破坏更改的建议,但我无法确定我需要做什么。据我所知,我的代码是旧的,没有使用管道运算符,但这就是我能弄明白的全部。

代码语言:javascript
复制
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));
EN

回答 1

Stack Overflow用户

发布于 2018-05-30 08:49:53

请参阅关于pipe syntax in the migration doc的小节,运算符必须通过调用.pipe()来调用,因此您需要执行如下操作

代码语言:javascript
复制
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,但是这只是一个兼容层,您应该真正使用管道语法。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50592218

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档