-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Labels
infraRelated to improving the codebaseRelated to improving the codebase
Description
We merged #20 to unblock people, but I think there's still some improvements that could be made.
HomeViewModel improvements
HomeUiStateshould be refactored to expose anApiResponseinstead of just a data class with data.- This way, in the UI we can do a
whenstatement, and show loading and error states appropriately.
- This way, in the UI we can do a
- Right now, we have a function
updateGameListthat we have to remember to call whenever we we receive an update fromscoreRepository.upcomingGamesFlow. But the whole point of flows is that so we don't have to remember to call these update functions and we can just have it update automatically!- So instead of making an update function, we should just use
map, to transform the flow exposed by the repository into ourUiStateaccordingly. If we do this, we can probably remove theinitblock entirely, since we'll just be sending down a mapped flow from the repository, so we don't need to attach any observers to it, we'll just exposing a read-only mapped version.
- So instead of making an update function, we should just use
- The date functions you made should go in a separate
DateUtil.ktfile. Also, you should try simplifying them usingDateTimeFormatter
ScoreRepository Improvements
Before asking for improvements for this one, I made a generic function toResult that looks like this:
/**
* Maps an ApolloResponse to a generic Kotlin result. It either provides the data with no errors, or
* a failure response containing the error message in the throwable.
*/
fun <T : Operation.Data> ApolloResponse<T>.toResult(): Result<T> {
if (hasErrors() || exception != null) {
return Result.failure(
exception?.cause ?: RuntimeException(
errors?.firstOrNull()?.message ?: "Unknown error occurred"
)
)
}
return try {
Result.success(dataOrThrow())
} catch (e: NoDataException) {
Result.failure(e)
}
}I think we should use this function for all of our Apollo calls, this way we can more easily see if it has errors or if the response is clean. So add this function to a file, then call it in ScoreRepository. Then make sure to handle the error and loading states appropriately. We can just fetch this data once when the app loads, in the init block of ScoreRepository. Use appScope for your repository scope, which I provided you with.
Metadata
Metadata
Assignees
Labels
infraRelated to improving the codebaseRelated to improving the codebase