diff --git a/redwood-protocol-host/api/redwood-protocol-host.api b/redwood-protocol-host/api/redwood-protocol-host.api index 30c2f84b12..2d7e45f554 100644 --- a/redwood-protocol-host/api/redwood-protocol-host.api +++ b/redwood-protocol-host/api/redwood-protocol-host.api @@ -48,16 +48,12 @@ public abstract class app/cash/redwood/protocol/host/ProtocolNode { } public final class app/cash/redwood/protocol/host/UiEvent { - public synthetic fun (IILjava/util/List;Ljava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V - public synthetic fun (IILjava/util/List;Ljava/util/List;Lkotlin/jvm/internal/DefaultConstructorMarker;)V - public fun equals (Ljava/lang/Object;)Z - public final fun getArgs ()Ljava/util/List; + public synthetic fun (II[Ljava/lang/Object;[Lkotlinx/serialization/SerializationStrategy;Lkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun getArgs ()[Ljava/lang/Object; public final fun getId-0HhLjSo ()I - public final fun getSerializationStrategies ()Ljava/util/List; + public final fun getSerializationStrategies ()[Lkotlinx/serialization/SerializationStrategy; public final fun getTag-RNF89mI ()I - public fun hashCode ()I public final fun toProtocol (Lkotlinx/serialization/json/Json;)Lapp/cash/redwood/protocol/Event; - public fun toString ()Ljava/lang/String; } public abstract interface class app/cash/redwood/protocol/host/UiEventSink { diff --git a/redwood-protocol-host/api/redwood-protocol-host.klib.api b/redwood-protocol-host/api/redwood-protocol-host.klib.api index 6fb53afc32..080892a31f 100644 --- a/redwood-protocol-host/api/redwood-protocol-host.klib.api +++ b/redwood-protocol-host/api/redwood-protocol-host.klib.api @@ -71,21 +71,18 @@ final class <#A: kotlin/Any> app.cash.redwood.protocol.host/ProtocolChildren { / } final class app.cash.redwood.protocol.host/UiEvent { // app.cash.redwood.protocol.host/UiEvent|null[0] - constructor (app.cash.redwood.protocol/Id, app.cash.redwood.protocol/EventTag, kotlin.collections/List = ..., kotlin.collections/List> = ...) // app.cash.redwood.protocol.host/UiEvent.|(app.cash.redwood.protocol.Id;app.cash.redwood.protocol.EventTag;kotlin.collections.List;kotlin.collections.List>){}[0] + constructor (app.cash.redwood.protocol/Id, app.cash.redwood.protocol/EventTag, kotlin/Array?, kotlin/Array>?) // app.cash.redwood.protocol.host/UiEvent.|(app.cash.redwood.protocol.Id;app.cash.redwood.protocol.EventTag;kotlin.Array?;kotlin.Array>?){}[0] final val args // app.cash.redwood.protocol.host/UiEvent.args|{}args[0] - final fun (): kotlin.collections/List // app.cash.redwood.protocol.host/UiEvent.args.|(){}[0] + final fun (): kotlin/Array? // app.cash.redwood.protocol.host/UiEvent.args.|(){}[0] final val id // app.cash.redwood.protocol.host/UiEvent.id|{}id[0] final fun (): app.cash.redwood.protocol/Id // app.cash.redwood.protocol.host/UiEvent.id.|(){}[0] final val serializationStrategies // app.cash.redwood.protocol.host/UiEvent.serializationStrategies|{}serializationStrategies[0] - final fun (): kotlin.collections/List> // app.cash.redwood.protocol.host/UiEvent.serializationStrategies.|(){}[0] + final fun (): kotlin/Array>? // app.cash.redwood.protocol.host/UiEvent.serializationStrategies.|(){}[0] final val tag // app.cash.redwood.protocol.host/UiEvent.tag|{}tag[0] final fun (): app.cash.redwood.protocol/EventTag // app.cash.redwood.protocol.host/UiEvent.tag.|(){}[0] - final fun equals(kotlin/Any?): kotlin/Boolean // app.cash.redwood.protocol.host/UiEvent.equals|equals(kotlin.Any?){}[0] - final fun hashCode(): kotlin/Int // app.cash.redwood.protocol.host/UiEvent.hashCode|hashCode(){}[0] final fun toProtocol(kotlinx.serialization.json/Json): app.cash.redwood.protocol/Event // app.cash.redwood.protocol.host/UiEvent.toProtocol|toProtocol(kotlinx.serialization.json.Json){}[0] - final fun toString(): kotlin/String // app.cash.redwood.protocol.host/UiEvent.toString|toString(){}[0] } final val app.cash.redwood.protocol.host/hostRedwoodVersion // app.cash.redwood.protocol.host/hostRedwoodVersion|{}hostRedwoodVersion[0] diff --git a/redwood-protocol-host/src/commonMain/kotlin/app/cash/redwood/protocol/host/UiEvent.kt b/redwood-protocol-host/src/commonMain/kotlin/app/cash/redwood/protocol/host/UiEvent.kt index 7f78ec6008..45b5bdc64f 100644 --- a/redwood-protocol-host/src/commonMain/kotlin/app/cash/redwood/protocol/host/UiEvent.kt +++ b/redwood-protocol-host/src/commonMain/kotlin/app/cash/redwood/protocol/host/UiEvent.kt @@ -19,7 +19,6 @@ import app.cash.redwood.protocol.Event import app.cash.redwood.protocol.EventSink import app.cash.redwood.protocol.EventTag import app.cash.redwood.protocol.Id -import dev.drewhamilton.poko.Poko import kotlinx.serialization.SerializationStrategy import kotlinx.serialization.json.Json @@ -27,27 +26,24 @@ import kotlinx.serialization.json.Json * A version of [Event] whose arguments have not yet been serialized to JSON and is thus * cheap to create on the UI thread. */ -@Poko public class UiEvent( public val id: Id, public val tag: EventTag, - public val args: List = emptyList(), - public val serializationStrategies: List> = emptyList(), + public val args: Array?, + public val serializationStrategies: Array>?, ) { - init { - check(args.size == serializationStrategies.size) { - "Properties 'args' and 'serializationStrategies' must have the same size. " + - "Found ${args.size} and ${serializationStrategies.size}" - } - } - /** Serialize [args] into a JSON model using [serializationStrategies] into an [Event]. */ public fun toProtocol(json: Json): Event { return Event( id = id, tag = tag, - args = List(args.size) { - json.encodeToJsonElement(serializationStrategies[it], args[it]) + args = if (args == null) { + emptyList() + } else { + val serializationStrategies = serializationStrategies!! + List(args.size) { i -> + json.encodeToJsonElement(serializationStrategies[i], args[i]) + } }, ) } diff --git a/redwood-tooling-codegen/src/main/kotlin/app/cash/redwood/tooling/codegen/protocolHostGeneration.kt b/redwood-tooling-codegen/src/main/kotlin/app/cash/redwood/tooling/codegen/protocolHostGeneration.kt index 94cd4cb38e..8b282bce07 100644 --- a/redwood-tooling-codegen/src/main/kotlin/app/cash/redwood/tooling/codegen/protocolHostGeneration.kt +++ b/redwood-tooling-codegen/src/main/kotlin/app/cash/redwood/tooling/codegen/protocolHostGeneration.kt @@ -570,11 +570,11 @@ private class OnClick( UiEvent( id, EventTag(3), - listOf( + arrayOf( arg0, arg1, ), - listOf( + arrayOf( serializer_0, serializer_1, ), @@ -621,14 +621,14 @@ private fun generateEventHandler( if (serializers.isEmpty()) { invoke.addCode( - "eventSink.sendEvent(%T(id, %T(%L)))", + "eventSink.sendEvent(%T(id, %T(%L), null, null))", ProtocolHost.UiEvent, Protocol.EventTag, trait.tag, ) } else { invoke.addCode( - "eventSink.sendEvent(⇥\n%T(⇥\nid,\n%T(%L),\nlistOf(⇥\n%L,\n⇤),\nlistOf(⇥\n%L,\n⇤),\n⇤),\n⇤)", + "eventSink.sendEvent(⇥\n%T(⇥\nid,\n%T(%L),\narrayOf(⇥\n%L,\n⇤),\narrayOf(⇥\n%L,\n⇤),\n⇤),\n⇤)", ProtocolHost.UiEvent, Protocol.EventTag, trait.tag, diff --git a/redwood-treehouse-host/src/commonTest/kotlin/app/cash/redwood/treehouse/FakeProtocolNode.kt b/redwood-treehouse-host/src/commonTest/kotlin/app/cash/redwood/treehouse/FakeProtocolNode.kt index fa24dd2653..ed06be40a3 100644 --- a/redwood-treehouse-host/src/commonTest/kotlin/app/cash/redwood/treehouse/FakeProtocolNode.kt +++ b/redwood-treehouse-host/src/commonTest/kotlin/app/cash/redwood/treehouse/FakeProtocolNode.kt @@ -40,7 +40,7 @@ internal class FakeProtocolNode( override fun apply(change: PropertyChange, eventSink: UiEventSink) { widget.label = (change.value as JsonPrimitive).content widget.onClick = { - eventSink.sendEvent(UiEvent(Id(1), EventTag(1))) + eventSink.sendEvent(UiEvent(Id(1), EventTag(1), null, null)) } }