refactor: simplify packetResponse using filterNotNull and firstOrNull

master
andrekir 2023-05-07 05:33:18 -03:00
rodzic d1ce014a88
commit 3bbe3fd7f7
1 zmienionych plików z 3 dodań i 4 usunięć

Wyświetl plik

@ -40,6 +40,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.launchIn
@ -156,10 +157,8 @@ class UIViewModel @Inject constructor(
_ourNodeInfo.value = it
}.launchIn(viewModelScope)
combine(_meshLog, requestId) { packet, requestId ->
requestId?.run { packet.lastOrNull { it.meshPacket?.decoded?.requestId == requestId } }
}.onEach {
_packetResponse.value = it
combine(meshLog, requestId.filterNotNull()) { packet, id ->
_packetResponse.value = packet.firstOrNull { it.meshPacket?.decoded?.requestId == id }
}.launchIn(viewModelScope)
debug("ViewModel created")