Optimize source settings flow

This commit is contained in:
Syer10
2021-11-07 14:51:08 -05:00
parent 54c9a10d6b
commit 192b555235

View File

@@ -15,6 +15,7 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.drop
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
@@ -40,11 +41,9 @@ class SourceSettingsViewModel @Inject constructor(
subscriptions.forEach { it.cancel() }
subscriptions.clear()
subscriptions += settings.map { setting ->
setting.state.drop(1).onEach {
if (it != null) {
sourceHandler.setSourceSetting(params.sourceId, setting.index, it)
getSourceSettings()
}
setting.state.drop(1).filterNotNull().onEach {
sourceHandler.setSourceSetting(params.sourceId, setting.index, it)
getSourceSettings()
}.launchIn(scope)
}
}.launchIn(scope)