如何使用map运算符作为mergeMap?

时间:2018-06-11 23:57:11

标签: javascript rxjs observable

现在不推荐使用mergeMap,并且源中包含此注释:

/* @deprecated resultSelector no longer supported, use inner map instead */

如何使用"内部地图"代替?我想这意味着在map内使用.pipe运算符函数,但是observable不会像mergeMap一样展平。

obs1$.pipe(map(() => obs2$)).subscribe(r => console.log(r === obs2$))
// > true

那么,没有它的mergeMap相当于怎样?

1 个答案:

答案 0 :(得分:5)

你仍然使用mergeMap,它只是弃用的resultSelector函数。

这个不被弃用:

export function mergeMap<T, R>(project: (value: T, index: number) => ObservableInput<R>, concurrent?: number): OperatorFunction<T, R>;

但是,这些是:

/** @deprecated resultSelector no longer supported, use inner map instead */
export function mergeMap<T, R>(project: (value: T, index: number) => ObservableInput<R>, resultSelector: undefined, concurrent?: number): OperatorFunction<T, R>;
/** @deprecated resultSelector no longer supported, use inner map instead */
export function mergeMap<T, I, R>(project: (value: T, index: number) => ObservableInput<I>, resultSelector: (outerValue: T, innerValue: I, outerIndex: number, innerIndex: number) => R, concurrent?: number): OperatorFunction<T, R>;