前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >rxjs里concatMap operators的用法

rxjs里concatMap operators的用法

作者头像
Jerry Wang
发布2020-10-27 15:04:27
7070
发布2020-10-27 15:04:27
举报

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.

例子:

代码语言:javascript
复制
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,然后连接在一起。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020-10-18 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档