如何阅读 RxJs mergeMap 大理石图 [英] How to read the RxJs mergeMap marble diagram

查看:38
本文介绍了如何阅读 RxJs mergeMap 大理石图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决方案

mergeMapi 映射到由字符串 10*i--10 表示的可观察对象*i--10*i-|.此字符串包含 marble 语法,表示在虚拟机上发生的事件时间.

文档中使用的主要字符是:

<块引用>
  • - 帧:1 个帧"虚拟时间流逝
  • [a-z0-9] 任何字母数字字符:表示生产者信号 next() 发出的值.
  • | complete:成功完成一个 observable.这是可观察的生产者信号complete().
  • # 错误:终止可观察对象的错误.这是可观察的生产者信号error().

所以 10--10--10-| 将是图片中第二个 observable 的表达式.例如

const tens$ = timer(0, 4).pipe(take(3), mapTo(10))

10*i--10*i--10*i-| 是将 10--10--10 发出的每个值相乘时得到的可观察值的表达式-|i.例如

of(1,3,5).pipe(mergeMap(i => tens$.pipe(map(v => v*i))))

In this marble diagram for mergeMap, how do you read this expression?

// Kind of, looks like an em-dash near the end
mergeMap(i => 10*i--10*i--10*i--|)

解决方案

mergeMap maps i to an observable represented by the string 10*i--10*i--10*i-|. This string contains marble syntax representing events happening over virtual time.

The main characters used in the documentation are:

  • - frame: 1 "frame" of virtual time passing
  • [a-z0-9] any alphanumeric character: Represents a value being emitted by the producer signaling next().
  • | complete: The successful completion of an observable. This is the observable producer signaling complete().
  • # error: An error terminating the observable. This is the observable producer signaling error().

So 10--10--10-| would be an expression for the second observable in the picture. e.g.

const tens$ = timer(0, 4).pipe(take(3), mapTo(10))

10*i--10*i--10*i-| is an expression for the observable you get when you multiply every value emitted by 10--10--10-| with i. e.g.

of(1,3,5).pipe(
  mergeMap(i => tens$.pipe(map(v => v*i)))
)

这篇关于如何阅读 RxJs mergeMap 大理石图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆