Skip to content

Commit

Permalink
fixes to event serialization for debuger
Browse files Browse the repository at this point in the history
  • Loading branch information
Nek-12 committed Mar 6, 2024
1 parent c804e39 commit 8eff7c7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package pro.respawn.flowmvi.debugger.model

import com.benasher44.uuid.Uuid
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.UseSerializers
import pro.respawn.flowmvi.api.MVIAction
Expand All @@ -13,30 +14,36 @@ import pro.respawn.flowmvi.debugger.name
import pro.respawn.flowmvi.debugger.serializers.UUIDSerializer

@Serializable
@SerialName("client")
public sealed interface ClientEvent : MVIIntent {

@Serializable
@SerialName("connected")
public data class StoreConnected(
val name: String,
val id: Uuid,
) : ClientEvent

@Serializable
@SerialName("disconnected")
public data class StoreDisconnected(
val id: Uuid,
) : ClientEvent

@Serializable
@SerialName("started")
public data class StoreStarted(
val name: String,
) : ClientEvent

@Serializable
@SerialName("stopped")
public data class StoreStopped(
val name: String,
) : ClientEvent

@Serializable
@SerialName("intent")
public data class StoreIntent(
val name: String,
val data: String,
Expand All @@ -46,6 +53,7 @@ public sealed interface ClientEvent : MVIIntent {
}

@Serializable
@SerialName("action")
public data class StoreAction(
val name: String,
val data: String,
Expand All @@ -55,6 +63,7 @@ public sealed interface ClientEvent : MVIIntent {
}

@Serializable
@SerialName("state_change")
public data class StoreStateChanged(
val from: StoreState,
val to: StoreState,
Expand All @@ -64,16 +73,19 @@ public sealed interface ClientEvent : MVIIntent {
}

@Serializable
@SerialName("unsubscribed")
public data class StoreUnsubscribed(
val newSubscriptionCount: Int,
) : ClientEvent

@Serializable
@SerialName("subscribed")
public data class StoreSubscribed(
val newSubscriptionCount: Int,
) : ClientEvent

@Serializable
@SerialName("exception")
public data class StoreException(
val name: String,
val message: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import kotlinx.coroutines.supervisorScope
import pro.respawn.flowmvi.api.Container
import pro.respawn.flowmvi.debugger.model.ClientEvent
import pro.respawn.flowmvi.debugger.model.ClientEvent.StoreDisconnected
import pro.respawn.flowmvi.debugger.model.ServerEvent
import pro.respawn.flowmvi.debugger.server.ServerAction.SendClientEvent
import pro.respawn.flowmvi.debugger.server.ServerIntent.EventReceived
import pro.respawn.flowmvi.debugger.server.ServerIntent.ServerStarted
Expand Down Expand Up @@ -49,7 +50,7 @@ internal object DebugServer : Container<ServerState, ServerIntent, ServerAction>
actions
.filterIsInstance<SendClientEvent>()
.filter { it.client == storeId }
.collect { sendSerialized(it.event) }
.collect { sendSerialized<ServerEvent>(it.event) }
}
launch {
while (true) {
Expand Down

0 comments on commit 8eff7c7

Please sign in to comment.