当前位置:网站首页>Rxjs Observable. Execute logical analysis of pipe passing in multiple operators
Rxjs Observable. Execute logical analysis of pipe passing in multiple operators
2022-06-11 10:50:00 【Hua Weiyun】
Test code :
fromEvent(this.test, 'click').pipe(map( event => event.timeStamp), mapTo(1)).subscribe((event) => console.log(event));pipe The two input operations of the operation :
The input parameter is an array , Contains two elements :
Use the original Observable As input , Perform these two operations :
Array of reduce It's a native method :
Here's the code , It introduces reduce Usage of :
<html><script>var a = [1,2,3,4];function fn(pre, cur, index, arr){ console.log(`previous: ${pre}, cur: ${cur}, index: ${index}, whole arr: ${arr}`); return pre + cur;}console.log(a.reduce( fn, 0));</script></html>reduce Take two parameters , The first argument is a function , This function receives 4 Three input parameters ,previous,current,index and array:
- previous: The previous round reduce Iteration value , If the first round , Then the value is the second parameter , That's the initial value
- current: The current round of reduce Iteration value . for example ,array Element is 1,2,3,4, be reduce Every iteration ,current Values, respectively 1,2,3,4
- index: Iterated index values
- array: call reduce The original array of , With the previous index Parameters , Access to the contents of the entire array

In actual use ,previous and current These two parameters are used most .
go back to pipeFromArray The implementation of the .

reduce First iteration :
prev yes input The initial value passed in ,fn It's input fns The first element of the array . That is the first one. map Back to operator:

There will be no specific implementation here map operation , But back to a new one Observable object , As a second round reduce The input to the iteration :

lift The way is to return the new Observable object :

mapTo The implementation of the :
after pipe Processed Observable, Finally, the application subscribes to , This is the final version of Observable:

边栏推荐
- 杰理之BLE SPP 开启 pin_code 功能【篇】
- 数字藏品系统开发源码搭建
- When installing mysql, an error occurred because msvcr120 could not be found DLL, unable to continue code resolution "
- 2022年安全月各类活动方案汇报(28页)
- Development and source code construction of digital collection system
- 错误的导航分类横条代码版本
- New Zealand is one of the best countries for road safety
- 安全相关网站推荐
- NewOJ Week 2---BCD
- SAP Spartacus Reference App Structure
猜你喜欢

Using ribbon to realize client load balancing

Leetcode 1961. 检查字符串是否为数组前缀

Jedislock redis distributed lock implementation

New Zealand is one of the best countries for road safety

NFT will change data ownership in the metauniverse

VMware install win7 virtual machine

Leetcode 1995. Statistics special quads (brute force enumeration)

Tiktok encounters cultural conflict in the UK, and many employees leave in a short time

Arbitrum 基础架构:快速入门

Installing mysql5.7 for Linux
随机推荐
NGUI,背包拖拽,以及随机克隆图片知识点
Dimension types for different CV tasks
VMware install win7 virtual machine
GameFi:您需要了解的关于“即玩即赚”游戏经济的一切
NGUI,地图放大缩小
MySQL下载安装使用-完整详细步骤
PHP仿网易云原创音乐分享平台网站源码
MySQL (IX)
Some understanding of inductive bias
beginning一款非常优秀的emlog主题
Remote monitoring project offline log specification
在线文件不落地转base64
Install MySQL version 5.7 or above on windows (install in compressed package)
Leetcode 1961. 检查字符串是否为数组前缀
Pyramidtnt: TNT with characteristic pyramid structure
6. how to automatically generate header file dependency -m
&lt; Pytorch series 4 & gt;: Constructing neural network model
SAP Spartacus Reference App Structure
基于C语言实现比赛评分系统
Update failed to update bytea type PostgreSQL