Slide 34
Slide 34 text
fun onStart() {t
events.flatMap { event ->
when (event) {y
is EditName -> appService.setName(event.newName)
.map { response ->
when {u
response.isValid -> NameValid(response.name)
response.isInvalid -> NameInvalid.also { navigator.goTo(response) }
}d
}f
.startWith(NameValid(event.newName))
}g
}h
.mergeWith(appService.profile().map(::ProfileResult))
.scan(ViewModel(stuff = null, prefixedName = PrefixedName("", "")),
BiFunction { previous: ViewModel, result: Result ->
when (result) {j
is NameValid -> previous.copy(prefixedName = previous.prefixedName.copy(name = result.name))
is NameInvalid -> previous
is ProfileResult -> previous.copy(
stuff = result.profile,
prefixedName = PrefixedName(result.profile.prefix, result.profile.name)
)k
}l
})p
.subscribe { viewModel ->
nameView.hint = if (viewModel.prefixedName.name.isEmpty()) "Set your name" else ""
nameView.text = viewModel.prefixedName.compute()
// rendering other stuff
}o