diff --git a/platform/collaboration-tools/src/com/intellij/collaboration/async/CoroutineUtil.kt b/platform/collaboration-tools/src/com/intellij/collaboration/async/CoroutineUtil.kt index c68970952672..2a1647c0fb7d 100644 --- a/platform/collaboration-tools/src/com/intellij/collaboration/async/CoroutineUtil.kt +++ b/platform/collaboration-tools/src/com/intellij/collaboration/async/CoroutineUtil.kt @@ -109,21 +109,6 @@ fun StateFlow.mapState( mapper: (value: T) -> M ): StateFlow = map { mapper(it) }.stateIn(scope, SharingStarted.Eagerly, mapper(value)) -@OptIn(ExperimentalCoroutinesApi::class) -@ApiStatus.Experimental -fun StateFlow.mapStateScoped(scope: CoroutineScope, - sharingStart: SharingStarted = SharingStarted.Eagerly, - mapper: CoroutineScope.(T) -> R): StateFlow { - 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 Flow.mapScoped(mapper: suspend CoroutineScope.(T) -> R): Flow { diff --git a/plugins/gitlab/src/org/jetbrains/plugins/gitlab/mergerequest/ui/GitLabProjectUIContextHolder.kt b/plugins/gitlab/src/org/jetbrains/plugins/gitlab/mergerequest/ui/GitLabProjectUIContextHolder.kt index 9664097a59e5..8d34fcb8740d 100644 --- a/plugins/gitlab/src/org/jetbrains/plugins/gitlab/mergerequest/ui/GitLabProjectUIContextHolder.kt +++ b/plugins/gitlab/src/org/jetbrains/plugins/gitlab/mergerequest/ui/GitLabProjectUIContextHolder.kt @@ -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() override val projectContext: StateFlow = - connectionManager.connectionState.mapStateScoped(cs) { connection -> + connectionManager.connectionState.mapScoped { connection -> connection?.let { GitLabProjectUIContext(project, it) } - } + }.stateIn(cs, SharingStarted.Eagerly, null) private val singleProjectAndAccountState: StateFlow?> = createSingleProjectAndAccountState(cs, projectsManager, accountManager)