1
在Diode中,如何處理Future.failure的效果? 該文檔(https://ochrons.github.io/diode/usage/Effects.html)很清楚Ajax調用的成功值是如何用Pot.Ready更新模型的,但我想知道如何捕獲失敗並更新Pot.Failed。在二極管效應中處理Future.failure
在Diode中,如何處理Future.failure的效果? 該文檔(https://ochrons.github.io/diode/usage/Effects.html)很清楚Ajax調用的成功值是如何用Pot.Ready更新模型的,但我想知道如何捕獲失敗並更新Pot.Failed。在二極管效應中處理Future.failure
使用普通效果,您需要使用map
和recover
的組合將成功的Future
和失敗的Future
轉換爲合適的操作。例如:
val eff = Effect(Ajax.get(url)
.map(r => NewMessages(r.responseText)))
.recover { case e => MessageLoadingFailed(e.getMessage) }
)
如果您正在使用AsyncAction
(或派生PotAction
)它提供了一個輔助方法effect
自動處理故障的未來,並創建一個PotFailed
狀態。
太棒了,那就是我一直在尋找的東西。 Cheers Ochrons =) – stackoverflowed