使用运行 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/