rxjs里concatMap operators的用法
Projects each source value to an Observable which is merged in the output Observable, in a serialized fashion waiting for each one to complete before merging the next.
將source Observable里的每個元素施加一個projection函數,這個projection函數返回一個新的Observable,然后將所有這些Observable flatten成另一個Observable.
Returns an Observable that emits items based on applying a function that you supply to each item emitted by the source Observable, where that function returns an (so-called “inner”) Observable. Each new inner Observable is concatenated with the previous inner Observable.
例子:
const clicks = fromEvent(document, 'click');const ioe = interval(1000);const mapfn = take(4);const comp = ioe.pipe(mapfn);const fn = ev => comp;const result = clicks.pipe( concatMap(fn));result.subscribe(x => console.log('diablo: ' +x));ioe是Observable:
mapfn是OperatorFunction:
comp是一個新的Observable:
fn函數接收任意類型的輸入變量,返回一個新的Observable:
測試結果:每點擊屏幕一次,順序打印0~4:
concatMap語義:每點擊一次,從interval Observable中拿出4個元素出來,生成4個新的Observable,然后連接在一起。
要獲取更多Jerry的原創文章,請關注公眾號"汪子熙":
總結
以上是生活随笔為你收集整理的rxjs里concatMap operators的用法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 期货交易入门知识 期货的含义
- 下一篇: 魔兽世界怀旧服大地的污染任务怎么完成 怀