我的異步操作往往是這個樣子:
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