【发布时间】:2019-08-02 07:20:50
【问题描述】:
react-native 新手,目前我正在开发链式 Promise。
myFunction(human, destination = null) {
const { navigation } = this.props;
const { onRefresh } = navigation.state.params;
this.setState({ isLoading: true });
return PeopleService.closeService(
human.humanId,
destinationPoint && destinationPoint.humanId,
)
.then((result) => {
if (result) {
PeopleHelperService.refreshInfo().then(() => {
if (onRefresh) {
onRefresh();
}
navigation.popToTop();
PopUp.showSuccess(
"Success message",
);
});
}
PopUp.showError(
"Failing message",
);
return null;
})
.finally(() => this.setState({ isLoading: false }));
}
我想要实现的目标是消除链式责任并使其变得简单而无需链式。
谁能指导我如何实现这一目标?一些文档和其他来源的链接对我了解如何制作非常有帮助。
更新: 似乎是 async/await 工作的答案。
【问题讨论】:
-
您的代码逻辑可能存在问题。如果
PeopleService.closeService()承诺解决了一个真实的result,那么将显示两个弹出窗口。我猜。
标签: javascript reactjs react-native chaining method-chaining