Rxjs - Operators - MergeMap

Signature

export declare function mergeMap<T, I, R>(
project: (value: T, index: number) => ObservableInput<I>,
resultSelector?: ((outerValue: T, innerValue: I, outerIndex: number, innerIndex: number) => R) | number, concurrent?: number): Observable<R>;

Parameters

因为是高阶流用的,所以project必须有

project是映射 怎么把外部流的每一个元素变成内部的子流方法
resultSelector 是把子流的元素再变化一次发给mergeMap后的操作
concurrent 就是并存merge的流的最大值

Sample

var letters = Rx.Observable.of('a', 'b', 'c');
var result = letters.mergeMap(x =>
Rx.Observable.interval(1000).map(i => x + i).take(5),
(oV, iV, oI, iI) => {
// console.log("innerValue", iV);
return "inner"+iV;
}, 2
);
result.subscribe(x => console.log(x));

解释