我的异步操作往往是这个样子:
anAsyncAction: process(function* anAsyncAction() {
self.isLoading = true;
const service = getEnv<IMyMarksPageStoreEnv>(self).myService;
try
{
yield service.doSomething();
}
finally
{
self.isLoading = false;
}
}),
然后我让视图处理什么祝酒显示:
toaster = Toaster.create({
position: Position.TOP
});
render() {
return <button disabled={this.props.store.isLoading} onClick={this.handleButtonClicked}>Do Async Thing</button>
}
handleButtonClicked =() => {
const store = this.props.store;
try
{
await store.anAsyncAction();
toaster.show({ message: "Saved!", intent: Intent.SUCCESS });
}
catch(e)
{
toaster.show({ message: "Whoops an error occured: "+e, intent: Intent.DANGER });
}
}
但是我开始觉得祝酒词处理应该存在于商店的异步尝试中,而不是视图,但是它的混合业务逻辑与视图,所以我不知道。
有什么建议吗?
你能否在你的回答中澄清一点点w或许参考了我的示例代码,您是否指“一个通知的生产者”? – mikeysee