Last active
February 10, 2020 00:29
-
-
Save OssamaDroid/aee64ce9b290dfdb2d5823d2afb95f81 to your computer and use it in GitHub Desktop.
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
// Result class of the SubmitName action | |
sealed class Result { | |
sealed class SubmitResult : Result() { | |
object Success: SubmitResult() | |
object InFlight: SubmitResult() | |
data class Failure(val errorMessage: String): SubmitResult() | |
} | |
} | |
private val submitName: ObservableTransformer<SubmitNameAction, SubmitResult> = | |
ObservableTransformer { actions -> | |
actions.flatMap { event -> | |
repository.sendName(event.name) // The asynchronous call | |
.andThen(Observable.just(SubmitResult.Success as SubmitResult)) | |
.onErrorReturn { SubmitResult.Failure(it.message ?: "Your error message") } | |
.observeOn(AndroidSchedulers.mainThread()) | |
.startWith(SubmitResult.InFlight) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment