当前位置:网站首页>Learn RX programming from me -- concat
Learn RX programming from me -- concat
2022-07-28 15:42:00 【I'm not a code God】
Business logic
- After entering the game scene , According to specific business scenarios and activity processes , You may need to pop up several pop ups , For example, invite friends to get rewards 、 Offline revenue 、 Divide the prize, etc .
- These pop-up boxes must pop up one by one , Cannot pop up at the same time .
Regular implementation
Because the logic of the pop-up box is asynchronous return , Therefore, it is inevitable to use the callback mechanism
Pseudo code
OpenDialog1(result1=>{
OpenDialog2(result2=>{
……
})
})Of course, the actual code will be more complex than this , Need more judgment and bifurcation
Use Rx Realization
Pseudo code
let dialogs = []
dialogs.push(rx.fromDialogBox(……))
dialogs.push(rx.fromDialogBox(……))
……
rx.concat(...dialogs).subscribe(……)among fromDialogBox It is an event flow extended by itself (Observable)
There are several benefits of doing this :
- Removed callback , Readability improvement
- You can change the order of pop-up frames at will
- You can remove a certain pop-up logic according to the change of demand at will
- In this event flow array , You can add other event flows , That is, other asynchronous operations are interspersed in the bullet sequence
- You can dynamically determine the number of pop-up frames that have been popped to determine the next operation ( Real time judgment dialogs.length)
let dialogs = []
if (condition1)
dialogs.push(rx.fromDialogBox(……))
if (condition2)
dialogs.push(rx.fromDialogBox(……))
……
if (dialogs.length<2)
dialogs.push(rx.fromDialogBox(……))
rx.concat(...dialogs).subscribe(……)In the above case , If you program in a traditional way , Readability will be poor , It's also easier to see bug, Your delicacies
边栏推荐
- 软件架构与设计(九)-----基于组件的架构
- 一文了解 Rainbond 云原生应用管理平台
- File and directory operations (5)
- Summary and arrangement of postgraduate entrance examination information of 211 colleges and universities nationwide
- 有道云笔记去除底部广告
- Return the two subscripts of the array according to the input target.
- Easyexcel complex header export (one to many)
- 正则表达式(4)
- 文件及目录操作(5)
- 8、实时数据备份和实时时钟功能实现
猜你喜欢

flowable工作流所有业务概念

Tencent interview -- please design a thread pool to implement sequential execution

百度提出动态自蒸馏方法,结合交互模型与双塔模型实现稠密段落检索

Self cultivation of programmers

融云实时社区解决方案

About the pictures inserted in the word document, only the following part is displayed

Explain the difference set, intersection set and union set of complex type set in detail.Net

How many tips do you know about using mock technology to help improve test efficiency?

AS如何不区分大小写去进行智能提示

Endnote 与word关联
随机推荐
Among the three "difficult and miscellaneous diseases" of machine learning, causal learning is the breakthrough | Liu Li, Chongqing University
融云实时社区解决方案
关闭独立窗口对其他窗口同时关闭的问题
Communication between client and server based on rsocket protocol
AS如何不区分大小写去进行智能提示
String (3)
Summary and arrangement of postgraduate entrance examination information of 985 colleges and universities nationwide
Tencent interview -- please design a thread pool to implement sequential execution
软件架构与设计(七)-----互动架构
FTP file transfer protocol
8. Realization of real-time data backup and real-time clock function
20. Channel allocation task implementation
华为全球员工总数创新高:19.4万人,研发人员占比近50%
19. Channel assignment task definition
VS使用技巧
基于RSocket协议实现客户端与服务端通信
使用Mock技术帮助提升测试效率的小tips,你知道几个?
Docker实现Redis Cluster(集群)模式 哈希槽分区进行亿级数据存储
Opencv - draw mask images of multiple instances
Pytorch - sequential and modulelist