当前位置:网站首页>跟我学Rx编程——Concat
跟我学Rx编程——Concat
2022-07-28 14:39:00 【我不是码神】
业务逻辑
- 游戏场景进入后,根据具体业务场景和活动进程,可能需要弹出若干的弹框,比如邀请好友获得的奖励、离线收益、瓜分大奖等等。
- 这些弹框必须逐个弹出,不能同时弹出。
常规实现
由于弹框的逻辑是异步返回,所以免不了使用回调机制
伪代码
OpenDialog1(result1=>{
OpenDialog2(result2=>{
……
})
})当然实际代码会比这个更复杂,需要更多的判断和分叉
使用Rx实现
伪代码
let dialogs = []
dialogs.push(rx.fromDialogBox(……))
dialogs.push(rx.fromDialogBox(……))
……
rx.concat(...dialogs).subscribe(……)其中fromDialogBox是自己扩展的一个事件流(Observable)
这么做的好处有几个:
- 去除了回调,可读性提升
- 可以随意改变弹框的顺序
- 可以随意的根据需求变化而去除某个弹框逻辑
- 在这个事件流数组中,可以添加其他事件流,即其他异步操作穿插在弹框序列中
- 可以动态判断已经弹出的弹框数量来决定下一步操作(实时判断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(……)在上述情况下,假如使用传统方式编程,可读性会很差,也更容易出现bug,你细品
边栏推荐
- Tencent interview -- please design a thread pool to implement sequential execution
- Flowable workflow all business concepts
- 爆肝整理 JVM 十大模块知识点总结,不信你还不懂
- ECCV 2022 | ssp: a new idea of small sample tasks with self-supporting matching
- Endnote 与word关联
- 3、基本常数和宏定义
- 位运算的一些操作
- 文件及目录操作(5)
- Vs dynamic library debugging
- 使用Mock技术帮助提升测试效率的小tips,你知道几个?
猜你喜欢

DataTables warning: table id=campaigntable - cannot reinitialize datatable. solve

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

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

Introduction to grpc

Idea debugging burpsuit plug-in

腾讯面试之--请你设计一个实现线程池顺序执行
![[jspwiki]jspwiki installation deployment and configuration](/img/3c/81a201bb80dcbb17d1c97b1a5bb215.png)
[jspwiki]jspwiki installation deployment and configuration

No files or folders found to process

MySQL 8.0 common (continuous update)

Opencv - closely combine multiple irregular small graphs into large graphs
随机推荐
leetcode-括号有效性问题
Editor in ArcGIS Pro
Stateflow逻辑系统建模
4、主程序和累积中断处理例程实现代码
No files or folders found to process
Share the HR experience of the first and second tier companies
多线程
Endnote is associated with word
10、相关数据累积任务实现
8. Realization of real-time data backup and real-time clock function
最小堆提升每次排序的效率
字符串(3)
Template injection summary
Opencv - closely combine multiple irregular small graphs into large graphs
QCustomPlot绘图工具常用方法
根据输入target,返回数组的两个下标。
CANoe使用教程
Leetcode - random set, longest multiclass subsequence
4.8 hd-gr GNSS navigation software source code
VirturalBox解决kernel driver问题