rxjs - 不推荐使用 combineLatest 以支持静态 combineLatest

标签 rxjs rxjs6

使用运行 rxjs 迁移工具后

rxjs-5-to-6-migrate -p src/tsconfig.app.json



我现在收到一个 linting 错误:

combineLatest is deprecated: Deprecated in favor of static combineLatest.



这是我运行迁移命令之前的代码:
this.store.combineLatest(
        this.store.select(lang.getCurrent),
        this.store.select(lang.getCurrentLocale)
    ).subscribe(([state, currentLang, locale]) => {
        this._language = session.language === currentLang ? '' : currentLang;
        this._locale = session.locale === locale ? '' : locale;
    });

运行迁移命令后我的代码:(当前呈现 linting 错误)
import {map, combineLatest} from 'rxjs/operators';
this.store.combineLatest(
        this.store.select(lang.getCurrent),
        this.store.select(lang.getCurrentLocale)
    ).subscribe(([state, currentLang, locale]) => {
        this._language = session.language === currentLang ? '' : currentLang;
        this._locale = session.locale === locale ? '' : locale;
    });

这个问题在这个stackoverflow问题中被问到了,但不够具体:Angular 6 ng lint duplicate errors and warnings, combineLatest is deprecated .

最佳答案

在 rxjs 6.5+

import { combineLatest } from 'rxjs';

combineLatest([a$, b$, c$]);

对于大多数应用程序,将 observables 数组映射到一个新值也是有帮助的:
combineLatest([a$, b$, c$]).pipe(
  map(([a$, b$, c$]) => ({
    a: a$, 
    b: b$, 
    c: c$
  }))
);
另见:https://www.learnrxjs.io/learn-rxjs/operators/combination/combinelatest

关于rxjs - 不推荐使用 combineLatest 以支持静态 combineLatest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50276165/

相关文章:

angular - 如何强制刷新 Angular2 中的 Observable 服务?

angular - 将数组中的值附加到 BehaviorSubject

javascript - 在 API 调用 NgRx Angular 之前检查商店

angular - 我可以使用 distinctUntilKeyChanged 来删除重复的对象吗?

rxjs - 如何防止在 RxJS 中进行多次提取调用?

javascript - RxJs6 - 静态合并可观察数组

javascript - RxJS:在 X 排放后更改 throttleTime

angular - 将 RxJS Observable 转换为 Promise

angular - 如何在rxjs6中注册路由监听并更改标题?

Angular 6 : Property 'catch' does not exist on type 'Observable<Response>' ?