业务逻辑
常规实现
由于弹框的逻辑是异步返回,所以免不了使用回调机制
伪代码
OpenDialog1(result1=>{
OpenDialog2(result2=>{
……
})
})
当然实际代码会比这个更复杂,需要更多的判断和分叉
使用Rx实现
伪代码
let dialogs = []
dialogs.push(rx.fromDialogBox(……))
dialogs.push(rx.fromDialogBox(……))
……
rx.concat(...dialogs).subscribe(……)
其中fromDialogBox是自己扩展的一个事件流(Observable)
这么做的好处有几个:
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,你细品
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有