使用后运行rxjs迁移工具
rxjs-5-to-6-migrate -p src/tsconfig.app.json
我现在得到一个linting错误:
combineLatest已弃用:不赞成使用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;
});
Run Code Online (Sandbox Code Playgroud)
运行迁移命令后的代码:(当前显示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;
});
Run Code Online (Sandbox Code Playgroud)
问题在这个stackoverflow问题中被问到,但它不够具体:Angular 6 ng lint重复错误和警告,combineLatest已被弃用 .
Sam*_*lib 51
我在这篇文章中找到了一个答案:RxJS 6:什么是新的,什么改变了?(来自官方文档):
解决方案是转换:
import { combineLatest } from 'rxjs/operators';
a$.pipe(combineLatest(b$, c$));
Run Code Online (Sandbox Code Playgroud)
成:
import { combineLatest } from 'rxjs';
combineLatest(a$, b$, c$);
Run Code Online (Sandbox Code Playgroud)
ofi*_*man 32
在rxjs 6.5中
import { combineLatest } from 'rxjs';
combineLatest([a$, b$, c$])
Run Code Online (Sandbox Code Playgroud)
小智 5
rxjs 版本 6.4.0
您应该从 RxJs 运算符导入映射运算符才能使其工作
combineLatest(a$, b$, c$).pipe(map([a, b, c]) => treat(a, b, c))
Run Code Online (Sandbox Code Playgroud)
似乎已被弃用,并且按照各种答案中的建议传递数组仍然会在 rxjs v.7.0.0弃用通知combineLatest
中引发错误
替换为
combineLatestWith
. 将在 v8 中删除。
对于使用 rxjs v.7.0.0 及以上版本的用户,您将需要使用combineLatestwith
input1Changes$.pipe(
combineLatestWith(input2Changes$)
)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
19127 次 |
最近记录: |