combineLatest 已弃用,取而代之的是静态 combineLatest
combineLatest deprecated in favor of static combineLatest
在运行之后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;
});
在这个 Whosebug 问题中提出了这个问题,但不够具体:Angular 6 ng lint duplicate errors and warnings, combineLatest is deprecated
.
已弃用!
请参考ofir fridman's answer for the correct syntaxs as of RxJs 6.5
我在这篇标题为:RxJS 6: What's new and what has changed? ( which comes from official docs) 的文章中找到了答案:
解决方法是转换:
import { combineLatest } from 'rxjs/operators';
a$.pipe(combineLatest(b$, c$));
进入:
import { combineLatest } from 'rxjs';
combineLatest([a$, b$, c$]);
rxjs 版本 6.4.0
你应该从 RxJs operators 导入 map operator 才能工作
combineLatest(a$, b$, c$).pipe(map([a, b, c]) => treat(a, b, c))
在 rxjs 6.5+
import { combineLatest } from 'rxjs';
combineLatest([a$, b$, c$]);
对于大多数应用程序,将可观察数组映射到新值也很有帮助:
combineLatest([a$, b$, c$]).pipe(
map(([a$, b$, c$]) => ({
a: a$,
b: b$,
c: c$
}))
);
另见:https://www.learnrxjs.io/learn-rxjs/operators/combination/combinelatest
combineLatest 与订阅者列表:
combineLatest([aSubscriber, bSubscriber]).pipe(map((aRes, bRes)=>{
// your business logic
}));
在运行之后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;
});
在这个 Whosebug 问题中提出了这个问题,但不够具体:Angular 6 ng lint duplicate errors and warnings, combineLatest is deprecated .
已弃用!
请参考ofir fridman's answer for the correct syntaxs as of RxJs 6.5
我在这篇标题为:RxJS 6: What's new and what has changed? ( which comes from official docs) 的文章中找到了答案:
解决方法是转换:
import { combineLatest } from 'rxjs/operators';
a$.pipe(combineLatest(b$, c$));
进入:
import { combineLatest } from 'rxjs';
combineLatest([a$, b$, c$]);
rxjs 版本 6.4.0
你应该从 RxJs operators 导入 map operator 才能工作
combineLatest(a$, b$, c$).pipe(map([a, b, c]) => treat(a, b, c))
在 rxjs 6.5+
import { combineLatest } from 'rxjs';
combineLatest([a$, b$, c$]);
对于大多数应用程序,将可观察数组映射到新值也很有帮助:
combineLatest([a$, b$, c$]).pipe(
map(([a$, b$, c$]) => ({
a: a$,
b: b$,
c: c$
}))
);
另见:https://www.learnrxjs.io/learn-rxjs/operators/combination/combinelatest
combineLatest 与订阅者列表:
combineLatest([aSubscriber, bSubscriber]).pipe(map((aRes, bRes)=>{
// your business logic
}));