Created
November 9, 2017 16:09
-
-
Save javipacheco/243a5ae15454db7a4eefb5dfce7a6e4e to your computer and use it in GitHub Desktop.
NewsActor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NewsActors(val apiService: ApiService, val uiService: NewsUiService) { | |
val mainActor = actor<Commands> { | |
var newsState: States.NewsState = States.NewsState(ListKW.empty()) | |
for (msg in channel) { | |
when (msg) { | |
is Commands.NewsGetItemsCommand -> | |
ServiceMonad().binding { | |
uiService.showLoading() | |
val news = apiService.getNews().bind() | |
newsState = newsState.copy(items = news.combineK(newsState.items)) | |
uiService.showNews(news).bind() | |
yields(Unit) | |
}.ev().fold({ ex -> | |
when(ex) { | |
is AkmeException.ApiException -> | |
notificationActor.sendBlocking(Notifications.NewsNotLoadedNotification) | |
is AkmeException.UiException -> | |
notificationActor.sendBlocking(Notifications.NewsUiErrorNotification) | |
} | |
}, {}) | |
is Commands.NewsShowMessageCommand -> | |
uiService.showMessage(msg.item) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment