javascript - 解决承诺 React Native
问题描述
我想在进入主屏幕之前执行一系列调度操作。
我觉得promise 可能是解决这个问题的正确方法,但是使用下面的代码,我们在完成每个功能(自动登录、工单、联系人、警报、合作伙伴)之前,向下走代码并更改屏幕。如何确保在最后一个 resetNavigation 命令之前完成了这 5 个操作?
Promise.resolve ( this.store.dispatch(autoLogin()) )
.then(function (response) {
store.dispatch(tickets());
})
.then(function (response) {
store.dispatch(contacts());
})
.then(function (response) {
store.dispatch(alerts());
})
.then(function (response) {
store.dispatch(partners());
})
.then(function (response) {
this.resetNavigation('HomeScreen');
})
解决方案
您可以在您的 components.And 中的合作伙伴操作影响的 shouldComponentUpdate() 方法中分派一个操作以再次导航。举个例子:
class ComponentEffectedByPartnerAction {
shouldComponentUpdate(){
this.resetNavigation('HomeScreen');
}
}
并删除你承诺的最后一步
Promise.resolve ( this.store.dispatch(autoLogin()) )
.then(function (response) {
store.dispatch(tickets());
})
.then(function (response) {
store.dispatch(contacts());
})
.then(function (response) {
store.dispatch(alerts());
})
.then(function (response) {
store.dispatch(partners());
})
.then(function (response) {
console.log("last chance")
//this.resetNavigation('HomeScreen');
})
推荐阅读
- typescript - 类型上不存在开玩笑的打字稿属性模拟
- google-apps-script - 从 Google 表格创建 Google 日历条目
- ios - 应用程序进入后台时 POST 请求错误
- python - Jupyter Notebook 中的 Flask 应用程序
- c++ - 使用参数化构造函数 C++ 动态分配对象数组
- codeblocks - 使用 sprintf() 时对 __mulhi3 的未定义引用 - Windows 上 Code::Blocks 中的 AVR GCC
- python - 使用 PyGame 中的操纵杆模块
- mysql - SQL Join 2 个表,即使没有匹配的数据
- firebase - Firestore:获取带有和不带有子集合数据的集合
- python - 在python的另一个文件中写入文件行