反对使用静态组合

运行 rxjs 迁移工具之后,使用

Rxjs-5-to-6-shift-p src/tsconfig.app.json

我现在得到一个错误:

反对: 反对使用静态 最新合并。

以下是运行迁移命令之前的代码:

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;
});

这个问题是在这个堆栈溢出问题中提出的,但它不够具体: 角6ng 线头重复错误和警告,组合最新是不推荐的 .

97386 次浏览

Deprecated!

Please refer to ofir fridman's answer for the correct syntaxs as of RxJs 6.5


I found an answer in this article titled: RxJS 6: What's new and what has changed? ( which comes from official docs):

The solution is to convert:

import { combineLatest } from 'rxjs/operators';


a$.pipe(combineLatest(b$, c$));

into:

import { combineLatest } from 'rxjs';


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

rxjs version 6.4.0

You should import map operator from RxJs operators for it to work

combineLatest(a$, b$, c$).pipe(map([a, b, c]) => treat(a, b, c))

In rxjs 6.5+

import { combineLatest } from 'rxjs';


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


And for most applications it's helpful to map the array of observables to a new value as well:

combineLatest([a$, b$, c$]).pipe(
map(([a$, b$, c$]) => ({
a: a$,
b: b$,
c: c$
}))
);

Also see: https://www.learnrxjs.io/learn-rxjs/operators/combination/combinelatest

combineLatest with a list of subscribers:

combineLatest([aSubscriber, bSubscriber]).pipe(map((aRes, bRes)=>{
// your business logic
}));
import { combineLatest } from 'rxjs';


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;
});

Seems combineLatest has been deprecated and passing an array as suggested in the various answers still throws the error in rxjs v.7.0.0 Deprecation Notice

Replaced with combineLatestWith. Will be removed in v8.

For those using rxjs v.7.0.0 and above you will need to use combineLatestwith

input1Changes$.pipe(
combineLatestWith(input2Changes$)
)