Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

rxjs - combineLatest deprecated in favor of static combineLatest

After running the rxjs migration tool using

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

I'm now getting a linting error:

combineLatest is deprecated: Deprecated in favor of static combineLatest.

Here is my code before running the migration command:

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

My code after running the migration command: (currently presenting a linting error)

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

The question was asked in this stackoverflow questions, but it was not specific enough: Angular 6 ng lint duplicate errors and warnings, combineLatest is deprecated .

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...