当前位置:网站首页>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
边栏推荐
- MATLAB不覆盖导入EXCEL
- 字符数组和字符串的区别
- 7、实时数据备份和实时时钟相关定义
- 全国985院校考研信息汇总整理
- 有道云笔记去除底部广告
- Pycharm - output exception of program run and default comment of added function
- How many of the top ten test tools in 2022 do you master
- Stateflow逻辑系统建模
- Summarize the knowledge points of the ten JVM modules. If you don't believe it, you still don't understand it
- Leetcode bracket validity problem
猜你喜欢

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

一篇文章了解RSocket协议

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

Communication between client and server based on rsocket protocol

Nftscan and nftplay have reached strategic cooperation in the field of NFT data

一文了解 Rainbond 云原生应用管理平台

使用Mock技术帮助提升测试效率的小tips,你知道几个?

生命的感悟

Among the three "difficult and miscellaneous diseases" of machine learning, causal learning is the breakthrough | Liu Li, Chongqing University

Editor in ArcGIS Pro
随机推荐
An article about rsocket protocol
try...except异常处理语句(6)
Summarize the knowledge points of the ten JVM modules. If you don't believe it, you still don't understand it
Give you a linked list, delete the penultimate node of the linked list, and return the head node of the linked list.
提速1200倍!MIT开发新一代药物研发AI,吊打老模型
Qt刷新UI界面问题
21. Definition of message processing task
Matlab does not overwrite importing Excel
如何通过adb打开和关闭飞行模式
德国电信否认加强与华为合作,并称过去3年已缩减与华为的合作
一篇文章了解RSocket协议
Installing CONDA and configuring Jupiter
MIT pointed out that the public pre training model should not be used indiscriminately
Close independent windows and close other windows at the same time
字符串(3)
Five connection modes of QT signal and slot
Pycharm - output exception of program run and default comment of added function
软件架构与设计(六)-----层次结构体
Vs dynamic library debugging
About how Simulink generates model coverage reports