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
results.scan(UIModel.idle(), { _, result -> | |
when (result) { | |
SubmitResult.InFlight, CheckNameResult.InFlight -> UIModel.inProgress() | |
SubmitResult.Success, CheckNameResult.Success -> UIModel.success() | |
is SubmitResult.Failure -> UIModel.error(result.errorMessage) | |
is CheckNameResult.Failure -> UIModel.error(result.errorMessage) | |
} | |
}) |
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> = |
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
private val transformSubmitNameEventToAction: ObservableTransformer<SubmitEvent, SubmitNameAction> = | |
ObservableTransformer { events -> | |
events.map { SubmitNameAction(it.name) } | |
} |
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
// Create Observable for button clicks | |
val submitEvents: Observable<SubmitEvent> = | |
submit_btn.clicks() | |
.map { SubmitEvent(edit_text.text.toString()) } | |
// Create Observable for text typing | |
val checkNameEvents: Observable<CheckNameEvent> = | |
edit_text.afterTextChangeEvents() | |
.map { CheckNameEvent(it.editable?.toString()) } |
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
// DON’T DO THIS | |
RxView.clicks(button) | |
.doOnNext { progressBar.setEnabled(true) } |