当前位置:网站首页>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
边栏推荐
猜你喜欢

vs动态库调试

Heap operation

Rongyun real-time community solution

ECCV 2022 | ssp: a new idea of small sample tasks with self-supporting matching

Endnote 与word关联

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

How to obtain and embed go binary execution package information

爆肝整理 JVM 十大模块知识点总结,不信你还不懂

800V高压系统

Minimum heap improves the efficiency of each sort
随机推荐
Baidu proposes a dynamic self distillation method to realize dense paragraph retrieval by combining interactive model and double tower model
1、开源GPS项目HD-GR GNSS的著作者
7. Definitions of real-time data backup and real-time clock
FTP文件传输协议
2022年最火的十大测试工具,你掌握了几个
Tencent interview -- please design a thread pool to implement sequential execution
VirturalBox解决kernel driver问题
全国211院校考研信息汇总整理
7、实时数据备份和实时时钟相关定义
如何通过adb打开和关闭飞行模式
Multithreading
800V高压系统
Execution process of SQL statement
Qt创建文件夹的两种方式区别
在OBS上进行H265推流
有道云笔记去除底部广告
多线程
An article about rsocket protocol
软件架构与设计(五)-----以数据为中心的架构
20、通道分配任务实现