refactor(tui-04): remove ConnectSession and DisconnectSession from Effect hierarchy

This commit is contained in:
2026-05-25 12:39:50 +04:00
parent 8b8f9c9379
commit cba0314197
4 changed files with 6 additions and 15 deletions
@@ -56,7 +56,7 @@ fun main(args: Array<String>) {
state = next
effects.forEach { effect ->
effectScope.launch {
EffectDispatcher(ws, effectScope) { runner.quit() }.dispatch(effect)
EffectDispatcher(ws) { runner.quit() }.dispatch(effect)
}
}
}
@@ -1,11 +1,8 @@
package com.correx.apps.tui.reducer
import com.correx.apps.server.protocol.ClientMessage
import com.correx.core.events.types.SessionId
sealed interface Effect {
data class SendWs(val message: ClientMessage) : Effect
data class ConnectSession(val sessionId: SessionId) : Effect
data object DisconnectSession: Effect
data object Quit : Effect
}
@@ -1,18 +1,14 @@
package com.correx.apps.tui.reducer
import com.correx.apps.tui.ws.TuiWsClient
import kotlinx.coroutines.CoroutineScope
class EffectDispatcher(
private val wsClient: TuiWsClient,
private val effectScope: CoroutineScope,
private val onQuit: () -> Unit,
) {
suspend fun dispatch(effect: Effect) {
when (effect) {
is Effect.SendWs -> wsClient.send(effect.message)
is Effect.ConnectSession -> wsClient.connectSession(effect.sessionId, effectScope)
Effect.DisconnectSession -> wsClient.disconnectSession()
Effect.Quit -> onQuit()
}
}
@@ -131,7 +131,7 @@ object SessionsReducer {
return sessionState.copy(
sessions = sessionState.sessions + summary,
selectedId = selected,
) to listOf(Effect.ConnectSession(msg.sessionId))
) to emptyList()
}
private fun processToolRejectedMessage(
@@ -300,21 +300,19 @@ object SessionsReducer {
sessions: SessionsState,
msg: ServerMessage.SessionFailed,
clock: () -> Long,
): Pair<SessionsState, List<Effect.DisconnectSession>> = touchSession(
): Pair<SessionsState, List<Effect>> = touchSession(
sessions,
msg.sessionId.value,
"FAILED",
clock,
) to listOf(Effect.DisconnectSession)
) to emptyList()
private fun processSessionCompletedMessage(
sessions: SessionsState,
msg: ServerMessage.SessionCompleted,
clock: () -> Long,
): Pair<SessionsState, List<Effect.DisconnectSession>> =
touchSession(sessions, msg.sessionId.value, "COMPLETED", clock) to listOf(
Effect.DisconnectSession,
)
): Pair<SessionsState, List<Effect>> =
touchSession(sessions, msg.sessionId.value, "COMPLETED", clock) to emptyList()
private fun processSessionPausedMessage(
msg: ServerMessage.SessionPaused,