[collab] drop strange non-structured-concurrency flow extension

GitOrigin-RevId: e520febb460529259cef2c4f741b69c293ce47ac
This commit is contained in:
Ivan Semenov
2023-06-19 17:33:16 +00:00
committed by intellij-monorepo-bot
parent 61ec7ce203
commit 9d53eebfb6
2 changed files with 5 additions and 18 deletions
@@ -109,21 +109,6 @@ fun <T, M> StateFlow<T>.mapState(
mapper: (value: T) -> M
): StateFlow<M> = map { mapper(it) }.stateIn(scope, SharingStarted.Eagerly, mapper(value))
@OptIn(ExperimentalCoroutinesApi::class)
@ApiStatus.Experimental
fun <T, R> StateFlow<T>.mapStateScoped(scope: CoroutineScope,
sharingStart: SharingStarted = SharingStarted.Eagerly,
mapper: CoroutineScope.(T) -> R): StateFlow<R> {
var nestedScope: CoroutineScope = scope.childScope()
val originalState = this
return drop(1).transformLatest { newValue ->
nestedScope.cancel()
nestedScope = scope.childScope()
val mapped = mapper(nestedScope, newValue)
emit(mapped)
}.stateIn(scope, sharingStart, mapper(nestedScope, originalState.value))
}
@OptIn(ExperimentalCoroutinesApi::class)
@ApiStatus.Experimental
fun <T, R> Flow<T>.mapScoped(mapper: suspend CoroutineScope.(T) -> R): Flow<R> {
@@ -2,7 +2,7 @@
package org.jetbrains.plugins.gitlab.mergerequest.ui
import com.intellij.collaboration.async.combineState
import com.intellij.collaboration.async.mapStateScoped
import com.intellij.collaboration.async.mapScoped
import com.intellij.collaboration.ui.toolwindow.ReviewToolwindowViewModel
import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
@@ -10,7 +10,9 @@ import com.intellij.openapi.project.Project
import com.intellij.util.childScope
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import org.jetbrains.plugins.gitlab.GitLabProjectsManager
import org.jetbrains.plugins.gitlab.api.GitLabProjectConnectionManager
@@ -32,9 +34,9 @@ internal class GitLabProjectUIContextHolder(
val accountManager: GitLabAccountManager = service<GitLabAccountManager>()
override val projectContext: StateFlow<GitLabProjectUIContext?> =
connectionManager.connectionState.mapStateScoped(cs) { connection ->
connectionManager.connectionState.mapScoped { connection ->
connection?.let { GitLabProjectUIContext(project, it) }
}
}.stateIn(cs, SharingStarted.Eagerly, null)
private val singleProjectAndAccountState: StateFlow<Pair<GitLabProjectMapping, GitLabAccount>?> =
createSingleProjectAndAccountState(cs, projectsManager, accountManager)