Reputation: 1534
In RXJS 6.5 the signature for combineLatest in the following code is deprecated:
import { combineLatest, interval } from 'rxjs';
import { map, take } from 'rxjs/operators';
const a$ = interval().pipe(
take(3),
map( x => `a: ${x}`)
);
const b$ = interval().pipe(
take(3),
map( x => x + 10 ),
map( x => `b: ${x}`)
);
combineLatest(a$, b$, (a, b) => `${a} / ${b}`)
.subscribe(x => console.log(x));
The output is:
a: 0 / b: 10
a: 1 / b: 10
a: 1 / b: 11
a: 2 / b: 11
a: 2 / b: 12
The problem here is the scheduler. The deprecation message does not really help me:
// With a scheduler (deprecated) /** @deprecated Passing a scheduler here is deprecated, use {@link subscribeOn} and/or {@link observeOn} instead */
How can I make this code compatible with RXJS 6.5?
Upvotes: 1
Views: 582
Reputation: 1069
I get the same error when passing a variable. You can ignore the pipe.
{
const values: Observable<any[]>[] = Object.values(subscriptions$);
return combineLatest<string[][]>(values).pipe(
map((variableValues) => {
let newInput = input;
variableValues.forEach((variableValue, i) => {
const key = keys[i];
const value = variableValue.find(v => v !== undefined);
const regex = new RegExp(`${this.escapeRegExp(key)}`, 'g');
newInput = newInput.replace(regex, value);
});
return newInput;
})
);
}
Deprecation message:
(alias) combineLatest<string[][]>(...observables: (Subscribable<never> | Subscribable<any> | PromiseLike<any> | InteropObservable<any> | ArrayLike<any> | Iterable<...> | SchedulerLike | ((...values: any[]) => string[][]))[]): Observable<...> (+38 overloads)
import combineLatest
@deprecated — Passing a scheduler here is deprecated, use {@link subscribeOn} and/or {@link observeOn} instead
'(...observables: (SchedulerLike | Subscribable<never> | Subscribable<any> | PromiseLike<any> | InteropObservable<any> | ArrayLike<...> | Iterable<...> | ((...values: any[]) => string[][]))[]): Observable<...>' is deprecatedts(6385)
Upvotes: 0
Reputation: 1534
Thanks to the comment of @cartant I can answer my own question now:
combineLatest([a$, b$])
.pipe(map( x => ((a, b) => `${a} / ${b}`)(...x)))
.subscribe(x => console.log(x));
Upvotes: 3