refactor(tui-04): remove ConnectSession and DisconnectSession from Effect hierarchy
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user