-
-
Save uteke/b9d06c02c9fa5f2221e7ec56b560b0cb to your computer and use it in GitHub Desktop.
Default action processor implementation
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 DefaultActionProcessor( | |
private val getUserListRepository: GetUserListRepository, | |
private val connectivityMonitor: ConnectivityMonitor, | |
private val logger: Logger, | |
private val tracker: Tracker, | |
) : ActionProcessor<Action, Mutation, Event> { | |
override fun invoke(action: Action): Flow<Pair<Mutation?, Event?>> = | |
flow { | |
when (action) { | |
is Action.Load -> load() | |
... | |
} | |
} | |
private suspend fun FlowCollector<Pair<Mutation?, Event?>>.load() { | |
emit(Mutation.ShowLoader to null) | |
when (val result = getUserListRepository()) { | |
is Success -> { | |
tracker.trackEvent(CatalogFetched) | |
emit(Mutation.ShowContent(users = result.users) to null) | |
} | |
is Empty -> { | |
tracker.trackEvent(EmptyCatalogFetched) | |
logger.error("empty catalog") | |
emit(Mutation.ShowContent(users = result.users) to null) | |
} | |
is Failure -> { | |
tracker.trackEvent(CatalogFetchFailed) | |
logger.error("failed catalog ${result.errorType}") | |
emit(Mutation.ShowError(result.errorType)) to null) | |
} | |
} | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment