Skip to content

Instantly share code, notes, and snippets.

View OssamaDroid's full-sized avatar

Ossama Bounnite OssamaDroid

  • Munich, Germany
View GitHub Profile
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)
}
})
// 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> =
private val transformSubmitNameEventToAction: ObservableTransformer<SubmitEvent, SubmitNameAction> =
ObservableTransformer { events ->
events.map { SubmitNameAction(it.name) }
}
// 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()) }
// DON’T DO THIS
RxView.clicks(button)
.doOnNext { progressBar.setEnabled(true) }