Rx.Observable.prototype.flatMapLatest(selector, [thisArg])
Transform the items emitted by an Observable into Observables, and mirror those items emitted by the most-recently transformed Observable.
The flatMapLatest
operator is similar to the flatMap
and concatMap
methods described above, however, rather than emitting all of the items emitted by all of the Observables that the operator generates by transforming items from the source Observable
, switchMap
instead emits items from each such transformed Observable
only until the next such Observable
is emitted, then it ignores the previous one and begins emitting items emitted by the new one.
参数
selector
(Function
): A transform function to apply to each source element. The callback has the following information:- the value of the element
- the index of the element
- the Observable object being subscribed
[thisArg]
(Any
): Object to use asthis
when executing the predicate.
返回值
(Observable
): An observable sequence which transforms the items emitted by an Observable into Observables, and mirror those items emitted by the most-recently transformed Observable.
例
var source = Rx.Observable
.range(1, 3)
.flatMapLatest(function(x) {
return Rx.Observable.from([x + 'a', x + 'b']);
});
var subscription = source.subscribe(
function (x) {
console.log('Next: %s', x);
},
function (err) {
console.log('Error: %s', err);
},
function () {
console.log('Completed');
});
// Next: 1a
// Next: 2a
// Next: 3a
// Next: 3b
// Completed