alexfacciorusso
10/18/2019, 10:37 AMprivate val _state = liveData<LoginViewState> {
coroutineScope {
launch {
usernamePasswordChannel.consumeEach { (username, password) ->
validateLoginDataUseCase.validateLoginData(
username,
password
).perform(latestValue!!).also { emit(it) }
}
}
launch {
isLoggingInChannel.consumeEach {
usernamePasswordChannel.value.let { (username, password) ->
performLoginUseCase.login(
username,
password
)
}.perform(latestValue!!).also { emit(it) }
}
}
}
}
It looks a bit odd, has anyone any suggestion about something I’m misusing or that can be optimised in terms of code?marstran
10/18/2019, 10:39 AMselect
to read from both channels without having consume them in two launch-tasks.Dominaezzz
10/18/2019, 10:48 AMasFlow
on the BroadcastChannel
and consumeAsFlow
on the Channel
. Then use flow operators to combine them.alexfacciorusso
10/18/2019, 10:54 AMDominaezzz
10/18/2019, 11:09 AMusernamePasswordChannel.asFlow().map { (username, password) ->
validateLoginDataUseCase.validateLoginData(
username,
password
).perform(latestValue!!)
}
?alexfacciorusso
10/18/2019, 11:09 AMDominaezzz
10/18/2019, 11:20 AMthe state changes using the data validator usecaseWhere is this in your code?
alexfacciorusso
10/18/2019, 11:21 AMperformLoginUseCase.login(...)
is when the login is performedAdam Powell
10/18/2019, 1:20 PM