diff --git a/redwood-protocol-guest/api/redwood-protocol-guest.api b/redwood-protocol-guest/api/redwood-protocol-guest.api index aba4d0c3eb..444ef3539b 100644 --- a/redwood-protocol-guest/api/redwood-protocol-guest.api +++ b/redwood-protocol-guest/api/redwood-protocol-guest.api @@ -6,9 +6,9 @@ public final class app/cash/redwood/protocol/guest/DefaultGuestProtocolAdapter : public fun appendCreate-kyz2zXs (II)V public fun appendModifierChange-z3jyS0k (ILapp/cash/redwood/Modifier;)V public fun appendMove-HpxY78w (IIIII)V - public fun appendPropertyChange-DxQz5cw (IILkotlinx/serialization/KSerializer;Ljava/lang/Object;)V - public fun appendPropertyChange-M7EZMwg (III)V - public fun appendPropertyChange-e3iP1vo (IIZ)V + public fun appendPropertyChange-13Ob0Yo (IIILkotlinx/serialization/KSerializer;Ljava/lang/Object;)V + public fun appendPropertyChange-ITsWdOQ (IIIZ)V + public fun appendPropertyChange-hzhmVHk (IIII)V public fun appendRemove-HpxY78w (IIIILjava/util/List;)V public fun emitChanges ()V public fun getJson ()Lkotlinx/serialization/json/Json; diff --git a/redwood-protocol-guest/api/redwood-protocol-guest.klib.api b/redwood-protocol-guest/api/redwood-protocol-guest.klib.api index 441b1642e9..9db367a6a1 100644 --- a/redwood-protocol-guest/api/redwood-protocol-guest.klib.api +++ b/redwood-protocol-guest/api/redwood-protocol-guest.klib.api @@ -42,13 +42,13 @@ final class app.cash.redwood.protocol.guest/DefaultGuestProtocolAdapter : app.ca final val widgetSystem // app.cash.redwood.protocol.guest/DefaultGuestProtocolAdapter.widgetSystem|{}widgetSystem[0] final fun (): app.cash.redwood.widget/WidgetSystem // app.cash.redwood.protocol.guest/DefaultGuestProtocolAdapter.widgetSystem.|(){}[0] - final fun <#A1: kotlin/Any?> appendPropertyChange(app.cash.redwood.protocol/Id, app.cash.redwood.protocol/PropertyTag, kotlinx.serialization/KSerializer<#A1>, #A1) // app.cash.redwood.protocol.guest/DefaultGuestProtocolAdapter.appendPropertyChange|appendPropertyChange(app.cash.redwood.protocol.Id;app.cash.redwood.protocol.PropertyTag;kotlinx.serialization.KSerializer<0:0>;0:0){0§}[0] + final fun <#A1: kotlin/Any?> appendPropertyChange(app.cash.redwood.protocol/Id, app.cash.redwood.protocol/WidgetTag, app.cash.redwood.protocol/PropertyTag, kotlinx.serialization/KSerializer<#A1>, #A1) // app.cash.redwood.protocol.guest/DefaultGuestProtocolAdapter.appendPropertyChange|appendPropertyChange(app.cash.redwood.protocol.Id;app.cash.redwood.protocol.WidgetTag;app.cash.redwood.protocol.PropertyTag;kotlinx.serialization.KSerializer<0:0>;0:0){0§}[0] final fun appendAdd(app.cash.redwood.protocol/Id, app.cash.redwood.protocol/ChildrenTag, kotlin/Int, app.cash.redwood.protocol.guest/ProtocolWidget) // app.cash.redwood.protocol.guest/DefaultGuestProtocolAdapter.appendAdd|appendAdd(app.cash.redwood.protocol.Id;app.cash.redwood.protocol.ChildrenTag;kotlin.Int;app.cash.redwood.protocol.guest.ProtocolWidget){}[0] final fun appendCreate(app.cash.redwood.protocol/Id, app.cash.redwood.protocol/WidgetTag) // app.cash.redwood.protocol.guest/DefaultGuestProtocolAdapter.appendCreate|appendCreate(app.cash.redwood.protocol.Id;app.cash.redwood.protocol.WidgetTag){}[0] final fun appendModifierChange(app.cash.redwood.protocol/Id, app.cash.redwood/Modifier) // app.cash.redwood.protocol.guest/DefaultGuestProtocolAdapter.appendModifierChange|appendModifierChange(app.cash.redwood.protocol.Id;app.cash.redwood.Modifier){}[0] final fun appendMove(app.cash.redwood.protocol/Id, app.cash.redwood.protocol/ChildrenTag, kotlin/Int, kotlin/Int, kotlin/Int) // app.cash.redwood.protocol.guest/DefaultGuestProtocolAdapter.appendMove|appendMove(app.cash.redwood.protocol.Id;app.cash.redwood.protocol.ChildrenTag;kotlin.Int;kotlin.Int;kotlin.Int){}[0] - final fun appendPropertyChange(app.cash.redwood.protocol/Id, app.cash.redwood.protocol/PropertyTag, kotlin/Boolean) // app.cash.redwood.protocol.guest/DefaultGuestProtocolAdapter.appendPropertyChange|appendPropertyChange(app.cash.redwood.protocol.Id;app.cash.redwood.protocol.PropertyTag;kotlin.Boolean){}[0] - final fun appendPropertyChange(app.cash.redwood.protocol/Id, app.cash.redwood.protocol/PropertyTag, kotlin/UInt) // app.cash.redwood.protocol.guest/DefaultGuestProtocolAdapter.appendPropertyChange|appendPropertyChange(app.cash.redwood.protocol.Id;app.cash.redwood.protocol.PropertyTag;kotlin.UInt){}[0] + final fun appendPropertyChange(app.cash.redwood.protocol/Id, app.cash.redwood.protocol/WidgetTag, app.cash.redwood.protocol/PropertyTag, kotlin/Boolean) // app.cash.redwood.protocol.guest/DefaultGuestProtocolAdapter.appendPropertyChange|appendPropertyChange(app.cash.redwood.protocol.Id;app.cash.redwood.protocol.WidgetTag;app.cash.redwood.protocol.PropertyTag;kotlin.Boolean){}[0] + final fun appendPropertyChange(app.cash.redwood.protocol/Id, app.cash.redwood.protocol/WidgetTag, app.cash.redwood.protocol/PropertyTag, kotlin/UInt) // app.cash.redwood.protocol.guest/DefaultGuestProtocolAdapter.appendPropertyChange|appendPropertyChange(app.cash.redwood.protocol.Id;app.cash.redwood.protocol.WidgetTag;app.cash.redwood.protocol.PropertyTag;kotlin.UInt){}[0] final fun appendRemove(app.cash.redwood.protocol/Id, app.cash.redwood.protocol/ChildrenTag, kotlin/Int, kotlin/Int, kotlin.collections/List) // app.cash.redwood.protocol.guest/DefaultGuestProtocolAdapter.appendRemove|appendRemove(app.cash.redwood.protocol.Id;app.cash.redwood.protocol.ChildrenTag;kotlin.Int;kotlin.Int;kotlin.collections.List){}[0] final fun emitChanges() // app.cash.redwood.protocol.guest/DefaultGuestProtocolAdapter.emitChanges|emitChanges(){}[0] final fun initChangesSink(app.cash.redwood.protocol/ChangesSink) // app.cash.redwood.protocol.guest/DefaultGuestProtocolAdapter.initChangesSink|initChangesSink(app.cash.redwood.protocol.ChangesSink){}[0] diff --git a/redwood-protocol-guest/src/commonMain/kotlin/app/cash/redwood/protocol/guest/DefaultGuestProtocolAdapter.kt b/redwood-protocol-guest/src/commonMain/kotlin/app/cash/redwood/protocol/guest/DefaultGuestProtocolAdapter.kt index 022e28d004..1c1f9b6e24 100644 --- a/redwood-protocol-guest/src/commonMain/kotlin/app/cash/redwood/protocol/guest/DefaultGuestProtocolAdapter.kt +++ b/redwood-protocol-guest/src/commonMain/kotlin/app/cash/redwood/protocol/guest/DefaultGuestProtocolAdapter.kt @@ -86,28 +86,31 @@ public class DefaultGuestProtocolAdapter( public override fun appendPropertyChange( id: Id, - tag: PropertyTag, + widgetTag: WidgetTag, + propertyTag: PropertyTag, serializer: KSerializer, value: T, ) { - changes.add(PropertyChange(id, tag, json.encodeToJsonElement(serializer, value))) + changes.add(PropertyChange(id, widgetTag, propertyTag, json.encodeToJsonElement(serializer, value))) } public override fun appendPropertyChange( id: Id, - tag: PropertyTag, + widgetTag: WidgetTag, + propertyTag: PropertyTag, value: Boolean, ) { - changes.add(PropertyChange(id, tag, JsonPrimitive(value))) + changes.add(PropertyChange(id, widgetTag, propertyTag, JsonPrimitive(value))) } @OptIn(ExperimentalSerializationApi::class) override fun appendPropertyChange( id: Id, - tag: PropertyTag, + widgetTag: WidgetTag, + propertyTag: PropertyTag, value: UInt, ) { - changes.add(PropertyChange(id, tag, JsonPrimitive(value))) + changes.add(PropertyChange(id, widgetTag, propertyTag, JsonPrimitive(value))) } override fun appendModifierChange(id: Id, value: Modifier) { diff --git a/redwood-protocol-guest/src/commonMain/kotlin/app/cash/redwood/protocol/guest/GuestProtocolAdapter.kt b/redwood-protocol-guest/src/commonMain/kotlin/app/cash/redwood/protocol/guest/GuestProtocolAdapter.kt index 7f76c8f3fb..45afe6e27f 100644 --- a/redwood-protocol-guest/src/commonMain/kotlin/app/cash/redwood/protocol/guest/GuestProtocolAdapter.kt +++ b/redwood-protocol-guest/src/commonMain/kotlin/app/cash/redwood/protocol/guest/GuestProtocolAdapter.kt @@ -80,7 +80,8 @@ public abstract class GuestProtocolAdapter( @RedwoodCodegenApi public abstract fun appendPropertyChange( id: Id, - tag: PropertyTag, + widgetTag: WidgetTag, + propertyTag: PropertyTag, serializer: KSerializer, value: T, ) @@ -88,7 +89,8 @@ public abstract class GuestProtocolAdapter( @RedwoodCodegenApi public abstract fun appendPropertyChange( id: Id, - tag: PropertyTag, + widgetTag: WidgetTag, + propertyTag: PropertyTag, value: Boolean, ) @@ -102,7 +104,8 @@ public abstract class GuestProtocolAdapter( @RedwoodCodegenApi public abstract fun appendPropertyChange( id: Id, - tag: PropertyTag, + widgetTag: WidgetTag, + propertyTag: PropertyTag, value: UInt, ) diff --git a/redwood-protocol-guest/src/commonTest/kotlin/app/cash/redwood/protocol/guest/GuestProtocolAdapterTest.kt b/redwood-protocol-guest/src/commonTest/kotlin/app/cash/redwood/protocol/guest/GuestProtocolAdapterTest.kt index 1f367743d3..b57f863393 100644 --- a/redwood-protocol-guest/src/commonTest/kotlin/app/cash/redwood/protocol/guest/GuestProtocolAdapterTest.kt +++ b/redwood-protocol-guest/src/commonTest/kotlin/app/cash/redwood/protocol/guest/GuestProtocolAdapterTest.kt @@ -63,7 +63,7 @@ class GuestProtocolAdapterTest { val expected = listOf( Create(Id(1), WidgetTag(5)), - PropertyChange(Id(1), PropertyTag(2), JsonPrimitive("PT10S")), + PropertyChange(Id(1), WidgetTag(5), PropertyTag(2), JsonPrimitive("PT10S")), ) assertThat(guestAdapter.takeChanges()).isEqualTo(expected) } diff --git a/redwood-protocol-guest/src/commonTest/kotlin/app/cash/redwood/protocol/guest/ProtocolTest.kt b/redwood-protocol-guest/src/commonTest/kotlin/app/cash/redwood/protocol/guest/ProtocolTest.kt index 0e48ac4c15..48e517da70 100644 --- a/redwood-protocol-guest/src/commonTest/kotlin/app/cash/redwood/protocol/guest/ProtocolTest.kt +++ b/redwood-protocol-guest/src/commonTest/kotlin/app/cash/redwood/protocol/guest/ProtocolTest.kt @@ -120,7 +120,7 @@ class ProtocolTest { // Text Create(Id(2), WidgetTag(3)), // text - PropertyChange(Id(2), PropertyTag(1), JsonPrimitive("hey")), + PropertyChange(Id(2), WidgetTag(3), PropertyTag(1), JsonPrimitive("hey")), ModifierChange(Id(2)), ChildrenChange.Add(Id(1), ChildrenTag(1), Id(2), 0), // Row @@ -129,7 +129,7 @@ class ProtocolTest { // Text Create(Id(4), WidgetTag(3)), // text - PropertyChange(Id(4), PropertyTag(1), JsonPrimitive("hello")), + PropertyChange(Id(4), WidgetTag(3), PropertyTag(1), JsonPrimitive("hello")), ModifierChange(Id(4)), ChildrenChange.Add(Id(3), ChildrenTag(1), Id(4), 0), ChildrenChange.Add(Id(1), ChildrenTag(1), Id(3), 1), @@ -151,29 +151,29 @@ class ProtocolTest { // Button Create(Id(1), WidgetTag(4)), // text - PropertyChange(Id(1), PropertyTag(1), JsonPrimitive("hi")), + PropertyChange(Id(1), WidgetTag(4), PropertyTag(1), JsonPrimitive("hi")), // onClick - PropertyChange(Id(1), PropertyTag(2), JsonPrimitive(false)), + PropertyChange(Id(1), WidgetTag(4), PropertyTag(2), JsonPrimitive(false)), // color - PropertyChange(Id(1), PropertyTag(3), JsonPrimitive(0u)), + PropertyChange(Id(1), WidgetTag(4), PropertyTag(3), JsonPrimitive(0u)), ModifierChange(Id(1)), ChildrenChange.Add(Id.Root, ChildrenTag.Root, Id(1), 0), // Button Create(Id(2), WidgetTag(4)), // text - PropertyChange(Id(2), PropertyTag(1), JsonPrimitive("hi")), + PropertyChange(Id(2), WidgetTag(4), PropertyTag(1), JsonPrimitive("hi")), // onClick - PropertyChange(Id(2), PropertyTag(2), JsonPrimitive(true)), + PropertyChange(Id(2), WidgetTag(4), PropertyTag(2), JsonPrimitive(true)), // color - PropertyChange(Id(2), PropertyTag(3), JsonPrimitive(0u)), + PropertyChange(Id(2), WidgetTag(4), PropertyTag(3), JsonPrimitive(0u)), ModifierChange(Id(2)), ChildrenChange.Add(Id.Root, ChildrenTag.Root, Id(2), 1), // Button2 Create(Id(3), WidgetTag(7)), // text - PropertyChange(Id(3), PropertyTag(1), JsonPrimitive("hi")), + PropertyChange(Id(3), WidgetTag(7), PropertyTag(1), JsonPrimitive("hi")), // onClick - PropertyChange(Id(3), PropertyTag(2), JsonPrimitive(true)), + PropertyChange(Id(3), WidgetTag(7), PropertyTag(2), JsonPrimitive(true)), ModifierChange(Id(3)), ChildrenChange.Add(Id.Root, ChildrenTag.Root, Id(3), 2), ), @@ -214,11 +214,11 @@ class ProtocolTest { // Button Create(Id(1), WidgetTag(4)), // text - PropertyChange(Id(1), PropertyTag(1), JsonPrimitive("state: 0")), + PropertyChange(Id(1), WidgetTag(4), PropertyTag(1), JsonPrimitive("state: 0")), // onClick - PropertyChange(Id(1), PropertyTag(2), JsonPrimitive(true)), + PropertyChange(Id(1), WidgetTag(4), PropertyTag(2), JsonPrimitive(true)), // color - PropertyChange(Id(1), PropertyTag(3), JsonPrimitive(0u)), + PropertyChange(Id(1), WidgetTag(4), PropertyTag(3), JsonPrimitive(0u)), ModifierChange(Id(1)), ChildrenChange.Add(Id.Root, ChildrenTag.Root, Id(1), 0), ), @@ -230,7 +230,7 @@ class ProtocolTest { assertThat(composition.awaitSnapshot()).isEqualTo( listOf( // text - PropertyChange(Id(1), PropertyTag(1), JsonPrimitive("state: 1")), + PropertyChange(Id(1), WidgetTag(4), PropertyTag(1), JsonPrimitive("state: 1")), ), ) @@ -240,9 +240,9 @@ class ProtocolTest { assertThat(composition.awaitSnapshot()).isEqualTo( listOf( // text - PropertyChange(Id(1), PropertyTag(1), JsonPrimitive("state: 2")), + PropertyChange(Id(1), WidgetTag(4), PropertyTag(1), JsonPrimitive("state: 2")), // text - PropertyChange(Id(1), PropertyTag(2), JsonPrimitive(false)), + PropertyChange(Id(1), WidgetTag(4), PropertyTag(2), JsonPrimitive(false)), ), ) @@ -252,7 +252,7 @@ class ProtocolTest { assertThat(composition.awaitSnapshot()).isEqualTo( listOf( // text - PropertyChange(Id(1), PropertyTag(1), JsonPrimitive("state: 3")), + PropertyChange(Id(1), WidgetTag(4), PropertyTag(1), JsonPrimitive("state: 3")), ), ) } @@ -283,9 +283,9 @@ class ProtocolTest { // Button2 Create(Id(1), WidgetTag(7)), // text - PropertyChange(Id(1), PropertyTag(1), JsonPrimitive("state: 0")), + PropertyChange(Id(1), WidgetTag(7), PropertyTag(1), JsonPrimitive("state: 0")), // onClick - PropertyChange(Id(1), PropertyTag(2), JsonPrimitive(true)), + PropertyChange(Id(1), WidgetTag(7), PropertyTag(2), JsonPrimitive(true)), ModifierChange(Id(1)), ChildrenChange.Add(Id.Root, ChildrenTag.Root, Id(1), 0), ), @@ -297,7 +297,7 @@ class ProtocolTest { assertThat(composition.awaitSnapshot()).isEqualTo( listOf( // text - PropertyChange(Id(1), PropertyTag(1), JsonPrimitive("state: 1")), + PropertyChange(Id(1), WidgetTag(7), PropertyTag(1), JsonPrimitive("state: 1")), ), ) } diff --git a/redwood-protocol-host/src/commonTest/kotlin/app/cash/redwood/protocol/host/HostProtocolAdapterTest.kt b/redwood-protocol-host/src/commonTest/kotlin/app/cash/redwood/protocol/host/HostProtocolAdapterTest.kt index b54266f631..63c11170aa 100644 --- a/redwood-protocol-host/src/commonTest/kotlin/app/cash/redwood/protocol/host/HostProtocolAdapterTest.kt +++ b/redwood-protocol-host/src/commonTest/kotlin/app/cash/redwood/protocol/host/HostProtocolAdapterTest.kt @@ -126,7 +126,8 @@ class HostProtocolAdapterTest { // Set Button's required color property. PropertyChange( id = Id(1), - tag = PropertyTag(3), + widgetTag = WidgetTag(4), + propertyTag = PropertyTag(3), value = JsonPrimitive(0), ), Add( @@ -155,8 +156,9 @@ class HostProtocolAdapterTest { val updateButtonText = listOf( PropertyChange( id = Id(1), + widgetTag = WidgetTag(4), // text - tag = PropertyTag(1), + propertyTag = PropertyTag(1), value = JsonPrimitive("hello"), ), ) @@ -230,7 +232,7 @@ class HostProtocolAdapterTest { ModifierChange(Id(2)), // Text Create(Id(3), WidgetTag(3)), - PropertyChange(Id(3), PropertyTag(1), JsonPrimitive("hello")), + PropertyChange(Id(3), WidgetTag(3), PropertyTag(1), JsonPrimitive("hello")), ModifierChange(Id(3)), Add(Id(2), ChildrenTag(1), Id(3), 0), Add(Id(1), ChildrenTag(1), Id(2), 0), @@ -241,7 +243,7 @@ class HostProtocolAdapterTest { // Validate we're tracking ID=3. host.sendChanges( listOf( - PropertyChange(Id(3), PropertyTag(1), JsonPrimitive("hey")), + PropertyChange(Id(3), WidgetTag(3), PropertyTag(1), JsonPrimitive("hey")), ), ) @@ -255,7 +257,7 @@ class HostProtocolAdapterTest { assertFailure { host.sendChanges( listOf( - PropertyChange(Id(3), PropertyTag(1), JsonPrimitive("sup")), + PropertyChange(Id(3), WidgetTag(3), PropertyTag(1), JsonPrimitive("sup")), ), ) }.isInstanceOf() diff --git a/redwood-protocol-host/src/commonTest/kotlin/app/cash/redwood/protocol/host/ProtocolFactoryTest.kt b/redwood-protocol-host/src/commonTest/kotlin/app/cash/redwood/protocol/host/ProtocolFactoryTest.kt index e3e23b8f11..84734a56a3 100644 --- a/redwood-protocol-host/src/commonTest/kotlin/app/cash/redwood/protocol/host/ProtocolFactoryTest.kt +++ b/redwood-protocol-host/src/commonTest/kotlin/app/cash/redwood/protocol/host/ProtocolFactoryTest.kt @@ -257,7 +257,7 @@ class ProtocolFactoryTest { val textInput = factory.widget(WidgetTag(5))!!.createNode(Id(1)) val throwingEventSink = UiEventSink { error(it) } - textInput.apply(PropertyChange(Id(1), PropertyTag(2), JsonPrimitive("PT10S")), throwingEventSink) + textInput.apply(PropertyChange(Id(1), WidgetTag(5), PropertyTag(2), JsonPrimitive("PT10S")), throwingEventSink) assertThat((textInput.widget.value as TextInputValue).customType).isEqualTo(10.seconds) } @@ -272,7 +272,7 @@ class ProtocolFactoryTest { ) val button = factory.widget(WidgetTag(4))!!.createNode(Id(1)) - val change = PropertyChange(Id(1), PropertyTag(345432)) + val change = PropertyChange(Id(1), WidgetTag(4), PropertyTag(345432)) val eventSink = UiEventSink { throw UnsupportedOperationException() } val t = assertFailsWith { button.apply(change, eventSink) @@ -292,7 +292,7 @@ class ProtocolFactoryTest { ) val button = factory.widget(WidgetTag(4))!!.createNode(Id(1)) - button.apply(PropertyChange(Id(1), PropertyTag(345432))) { throw UnsupportedOperationException() } + button.apply(PropertyChange(Id(1), WidgetTag(4), PropertyTag(345432))) { throw UnsupportedOperationException() } assertThat(handler.events.single()).isEqualTo("Unknown property 345432 for 4") } @@ -314,7 +314,7 @@ class ProtocolFactoryTest { val textInput = factory.widget(WidgetTag(5))!!.createNode(Id(1)) val eventSink = RecordingUiEventSink() - textInput.apply(PropertyChange(Id(1), PropertyTag(4), JsonPrimitive(true)), eventSink) + textInput.apply(PropertyChange(Id(1), WidgetTag(5), PropertyTag(4), JsonPrimitive(true)), eventSink) (textInput.widget.value as TextInputValue).onChangeCustomType!!.invoke(10.seconds) diff --git a/redwood-protocol/api/redwood-protocol.api b/redwood-protocol/api/redwood-protocol.api index 1f835c9bc7..413f025a97 100644 --- a/redwood-protocol/api/redwood-protocol.api +++ b/redwood-protocol/api/redwood-protocol.api @@ -326,11 +326,12 @@ public final class app/cash/redwood/protocol/ModifierTag$Companion { public final class app/cash/redwood/protocol/PropertyChange : app/cash/redwood/protocol/ValueChange { public static final field Companion Lapp/cash/redwood/protocol/PropertyChange$Companion; - public synthetic fun (IILkotlinx/serialization/json/JsonElement;Lkotlin/jvm/internal/DefaultConstructorMarker;)V + public synthetic fun (IIILkotlinx/serialization/json/JsonElement;Lkotlin/jvm/internal/DefaultConstructorMarker;)V public fun equals (Ljava/lang/Object;)Z public fun getId-0HhLjSo ()I - public final fun getTag-VGAaYLs ()I + public final fun getPropertyTag-VGAaYLs ()I public final fun getValue ()Lkotlinx/serialization/json/JsonElement; + public final fun getWidgetTag-BlhN7y0 ()I public fun hashCode ()I public fun toString ()Ljava/lang/String; } @@ -347,8 +348,8 @@ public synthetic class app/cash/redwood/protocol/PropertyChange$$serializer : ko } public final class app/cash/redwood/protocol/PropertyChange$Companion { - public final fun invoke-e3iP1vo (IILkotlinx/serialization/json/JsonElement;)Lapp/cash/redwood/protocol/PropertyChange; - public static synthetic fun invoke-e3iP1vo$default (Lapp/cash/redwood/protocol/PropertyChange$Companion;IILkotlinx/serialization/json/JsonElement;ILjava/lang/Object;)Lapp/cash/redwood/protocol/PropertyChange; + public final fun invoke-ITsWdOQ (IIILkotlinx/serialization/json/JsonElement;)Lapp/cash/redwood/protocol/PropertyChange; + public static synthetic fun invoke-ITsWdOQ$default (Lapp/cash/redwood/protocol/PropertyChange$Companion;IIILkotlinx/serialization/json/JsonElement;ILjava/lang/Object;)Lapp/cash/redwood/protocol/PropertyChange; public final fun serializer ()Lkotlinx/serialization/KSerializer; } diff --git a/redwood-protocol/api/redwood-protocol.klib.api b/redwood-protocol/api/redwood-protocol.klib.api index bb8f72c667..33bd0be5c2 100644 --- a/redwood-protocol/api/redwood-protocol.klib.api +++ b/redwood-protocol/api/redwood-protocol.klib.api @@ -226,10 +226,12 @@ final class app.cash.redwood.protocol/ModifierElement { // app.cash.redwood.prot final class app.cash.redwood.protocol/PropertyChange : app.cash.redwood.protocol/ValueChange { // app.cash.redwood.protocol/PropertyChange|null[0] final val id // app.cash.redwood.protocol/PropertyChange.id|{}id[0] final fun (): app.cash.redwood.protocol/Id // app.cash.redwood.protocol/PropertyChange.id.|(){}[0] - final val tag // app.cash.redwood.protocol/PropertyChange.tag|{}tag[0] - final fun (): app.cash.redwood.protocol/PropertyTag // app.cash.redwood.protocol/PropertyChange.tag.|(){}[0] + final val propertyTag // app.cash.redwood.protocol/PropertyChange.propertyTag|{}propertyTag[0] + final fun (): app.cash.redwood.protocol/PropertyTag // app.cash.redwood.protocol/PropertyChange.propertyTag.|(){}[0] final val value // app.cash.redwood.protocol/PropertyChange.value|{}value[0] final fun (): kotlinx.serialization.json/JsonElement // app.cash.redwood.protocol/PropertyChange.value.|(){}[0] + final val widgetTag // app.cash.redwood.protocol/PropertyChange.widgetTag|{}widgetTag[0] + final fun (): app.cash.redwood.protocol/WidgetTag // app.cash.redwood.protocol/PropertyChange.widgetTag.|(){}[0] final fun equals(kotlin/Any?): kotlin/Boolean // app.cash.redwood.protocol/PropertyChange.equals|equals(kotlin.Any?){}[0] final fun hashCode(): kotlin/Int // app.cash.redwood.protocol/PropertyChange.hashCode|hashCode(){}[0] @@ -245,7 +247,7 @@ final class app.cash.redwood.protocol/PropertyChange : app.cash.redwood.protocol } final object Companion { // app.cash.redwood.protocol/PropertyChange.Companion|null[0] - final fun invoke(app.cash.redwood.protocol/Id, app.cash.redwood.protocol/PropertyTag, kotlinx.serialization.json/JsonElement = ...): app.cash.redwood.protocol/PropertyChange // app.cash.redwood.protocol/PropertyChange.Companion.invoke|invoke(app.cash.redwood.protocol.Id;app.cash.redwood.protocol.PropertyTag;kotlinx.serialization.json.JsonElement){}[0] + final fun invoke(app.cash.redwood.protocol/Id, app.cash.redwood.protocol/WidgetTag, app.cash.redwood.protocol/PropertyTag, kotlinx.serialization.json/JsonElement = ...): app.cash.redwood.protocol/PropertyChange // app.cash.redwood.protocol/PropertyChange.Companion.invoke|invoke(app.cash.redwood.protocol.Id;app.cash.redwood.protocol.WidgetTag;app.cash.redwood.protocol.PropertyTag;kotlinx.serialization.json.JsonElement){}[0] final fun serializer(): kotlinx.serialization/KSerializer // app.cash.redwood.protocol/PropertyChange.Companion.serializer|serializer(){}[0] } } diff --git a/redwood-protocol/src/commonMain/kotlin/app/cash/redwood/protocol/protocol.kt b/redwood-protocol/src/commonMain/kotlin/app/cash/redwood/protocol/protocol.kt index a9ed1836de..3766e1fdf7 100644 --- a/redwood-protocol/src/commonMain/kotlin/app/cash/redwood/protocol/protocol.kt +++ b/redwood-protocol/src/commonMain/kotlin/app/cash/redwood/protocol/protocol.kt @@ -97,22 +97,29 @@ public sealed interface ValueChange : Change public class PropertyChange private constructor( @SerialName("id") private val _id: Int, + @SerialName("widget") + private val _widgetTag: Int, @SerialName("tag") private val _tag: Int, public val value: JsonElement = JsonNull, ) : ValueChange { override val id: Id get() = Id(_id) - /** Identifies which property changed on the widget with [id]. */ - public val tag: PropertyTag get() = PropertyTag(_tag) + /** Identifies the widget on which the property changed. */ + public val widgetTag: WidgetTag get() = WidgetTag(_widgetTag) + + /** Identifies which property changed on the widget. */ + public val propertyTag: PropertyTag get() = PropertyTag(_tag) public companion object { public operator fun invoke( id: Id, - /** Identifies which property changed on the widget with [id]. */ - tag: PropertyTag, + /** Identifies the widget on which the property changed. */ + widgetTag: WidgetTag, + /** Identifies which property changed on the widget. */ + propertyTag: PropertyTag, value: JsonElement = JsonNull, - ): PropertyChange = PropertyChange(id.value, tag.value, value) + ): PropertyChange = PropertyChange(id.value, widgetTag.value, propertyTag.value, value) } } diff --git a/redwood-protocol/src/commonTest/kotlin/app/cash/redwood/protocol/ProtocolTest.kt b/redwood-protocol/src/commonTest/kotlin/app/cash/redwood/protocol/ProtocolTest.kt index 120a9e5282..378c0aca5f 100644 --- a/redwood-protocol/src/commonTest/kotlin/app/cash/redwood/protocol/ProtocolTest.kt +++ b/redwood-protocol/src/commonTest/kotlin/app/cash/redwood/protocol/ProtocolTest.kt @@ -84,8 +84,8 @@ class ProtocolTest { ), ), ), - PropertyChange(Id(1), PropertyTag(2), JsonPrimitive("hello")), - PropertyChange(Id(1), PropertyTag(2), JsonNull), + PropertyChange(Id(1), WidgetTag(2), PropertyTag(2), JsonPrimitive("hello")), + PropertyChange(Id(1), WidgetTag(2), PropertyTag(2), JsonNull), ) val json = "" + "[" + @@ -95,8 +95,8 @@ class ProtocolTest { """["remove",{"id":4,"tag":3,"index":2,"count":1}],""" + """["remove",{"id":1,"tag":2,"index":3,"count":4,"removedIds":[5,6,7,8]}],""" + """["modifier",{"id":1,"elements":[[1,{}],[2,3],[3,[]],[4],[5]]}],""" + - """["property",{"id":1,"tag":2,"value":"hello"}],""" + - """["property",{"id":1,"tag":2}]""" + + """["property",{"id":1,"widget":2,"tag":2,"value":"hello"}],""" + + """["property",{"id":1,"widget":2,"tag":2}]""" + "]" assertJsonRoundtrip(ListSerializer(Change.serializer()), changes, json) } diff --git a/redwood-protocol/src/commonTest/kotlin/app/cash/redwood/protocol/SnapshotChangeListTest.kt b/redwood-protocol/src/commonTest/kotlin/app/cash/redwood/protocol/SnapshotChangeListTest.kt index be853ddde7..5505ed7219 100644 --- a/redwood-protocol/src/commonTest/kotlin/app/cash/redwood/protocol/SnapshotChangeListTest.kt +++ b/redwood-protocol/src/commonTest/kotlin/app/cash/redwood/protocol/SnapshotChangeListTest.kt @@ -32,7 +32,7 @@ class SnapshotChangeListTest { listOf( Create(Id(1), WidgetTag(1)), ModifierChange(Id(1), emptyList()), - PropertyChange(Id(1), PropertyTag(1), JsonPrimitive("Hello")), + PropertyChange(Id(1), WidgetTag(1), PropertyTag(1), JsonPrimitive("Hello")), Add(Id.Root, ChildrenTag.Root, Id(1), 0), ), ) @@ -43,7 +43,7 @@ class SnapshotChangeListTest { |[ |{"type":"create","id":1,"tag":1}, |{"type":"modifier","id":1}, - |{"type":"property","id":1,"tag":1,"value":"Hello"}, + |{"type":"property","id":1,"widget":1,"tag":1,"value":"Hello"}, |{"type":"add","id":0,"tag":1,"childId":1,"index":0} |] """.trimMargin().replace("\n", ""), @@ -60,7 +60,7 @@ class SnapshotChangeListTest { Create(Id(1), WidgetTag(1)), ModifierChange(Id(1), emptyList()), Move(Id.Root, ChildrenTag.Root, 1, 2, 3), - PropertyChange(Id(1), PropertyTag(1), JsonPrimitive("Hello")), + PropertyChange(Id(1), WidgetTag(1), PropertyTag(1), JsonPrimitive("Hello")), Add(Id.Root, ChildrenTag.Root, Id(1), 0), Remove(Id.Root, ChildrenTag.Root, 1, 2, listOf(Id(3), Id(4))), ), diff --git a/redwood-testing/src/commonTest/kotlin/app/cash/redwood/testing/ViewTreesTest.kt b/redwood-testing/src/commonTest/kotlin/app/cash/redwood/testing/ViewTreesTest.kt index 6a4c94b1e0..a0f4b6e76d 100644 --- a/redwood-testing/src/commonTest/kotlin/app/cash/redwood/testing/ViewTreesTest.kt +++ b/redwood-testing/src/commonTest/kotlin/app/cash/redwood/testing/ViewTreesTest.kt @@ -86,22 +86,22 @@ class ViewTreesTest { Create(Id(2), WidgetTag(1)), ModifierChange(Id(2), emptyList()), Create(Id(3), WidgetTag(3)), - PropertyChange(Id(3), PropertyTag(1), JsonPrimitive("One Fish")), + PropertyChange(Id(3), WidgetTag(3), PropertyTag(1), JsonPrimitive("One Fish")), ModifierChange(Id(3), emptyList()), Add(Id(2), ChildrenTag(1), Id(3), 0), Create(Id(4), WidgetTag(3)), - PropertyChange(Id(4), PropertyTag(1), JsonPrimitive("Two Fish")), + PropertyChange(Id(4), WidgetTag(3), PropertyTag(1), JsonPrimitive("Two Fish")), ModifierChange(Id(4), emptyList()), Add(Id(2), ChildrenTag(1), Id(4), 1), Add(Id(1), ChildrenTag(1), Id(2), 0), Create(Id(5), WidgetTag(1)), ModifierChange(Id(5), emptyList()), Create(Id(6), WidgetTag(3)), - PropertyChange(Id(6), PropertyTag(1), JsonPrimitive("Red Fish")), + PropertyChange(Id(6), WidgetTag(3), PropertyTag(1), JsonPrimitive("Red Fish")), ModifierChange(Id(6), emptyList()), Add(Id(5), ChildrenTag(1), Id(6), 0), Create(Id(7), WidgetTag(3)), - PropertyChange(Id(7), PropertyTag(1), JsonPrimitive("Blue Fish")), + PropertyChange(Id(7), WidgetTag(3), PropertyTag(1), JsonPrimitive("Blue Fish")), ModifierChange(Id(7), emptyList()), Add(Id(5), ChildrenTag(1), Id(7), 1), Add(Id(1), ChildrenTag(1), Id(5), 1), diff --git a/redwood-tooling-codegen/src/main/kotlin/app/cash/redwood/tooling/codegen/protocolGuestGeneration.kt b/redwood-tooling-codegen/src/main/kotlin/app/cash/redwood/tooling/codegen/protocolGuestGeneration.kt index 6b9730700b..59bf289cc2 100644 --- a/redwood-tooling-codegen/src/main/kotlin/app/cash/redwood/tooling/codegen/protocolGuestGeneration.kt +++ b/redwood-tooling-codegen/src/main/kotlin/app/cash/redwood/tooling/codegen/protocolGuestGeneration.kt @@ -207,13 +207,13 @@ internal class ProtocolButton( } override fun text(text: String?) { - this.guestAdapter.appendPropertyChange(this.id, PropertyTag(1), serializer_0, text) + this.guestAdapter.appendPropertyChange(this.id, WidgetTag(3), PropertyTag(1), serializer_0, text) } override fun onClick(onClick: (() -> Unit)?) { val onClickSet = onClick != null if (onClickSet != (this.onClick != null)) { - guestAdapter.appendPropertyChange(this.id, PropertyTag(3), onClickSet) + guestAdapter.appendPropertyChange(this.id, WidgetTag(3), PropertyTag(3), onClickSet) } this.onClick = onClick } @@ -290,7 +290,9 @@ internal fun generateProtocolWidget( // Work around https://github.com/Kotlin/kotlinx.serialization/issues/2713. if (traitTypeName == U_INT) { addStatement( - "this.guestAdapter.appendPropertyChange(this.id, %T(%L), %N)", + "this.guestAdapter.appendPropertyChange(this.id, %T(%L), %T(%L), %N)", + Protocol.WidgetTag, + widget.tag, Protocol.PropertyTag, trait.tag, trait.name, @@ -300,7 +302,9 @@ internal fun generateProtocolWidget( nextSerializerId++ } addStatement( - "this.guestAdapter.appendPropertyChange(this.id, %T(%L), serializer_%L, %N)", + "this.guestAdapter.appendPropertyChange(this.id, %T(%L), %T(%L), serializer_%L, %N)", + Protocol.WidgetTag, + widget.tag, Protocol.PropertyTag, trait.tag, serializerId, @@ -342,7 +346,9 @@ internal fun generateProtocolWidget( "true" } addStatement( - "this.guestAdapter.appendPropertyChange(this.id, %T(%L), %L)", + "this.guestAdapter.appendPropertyChange(this.id, %T(%L), %T(%L), %L)", + Protocol.WidgetTag, + widget.tag, Protocol.PropertyTag, trait.tag, newValue, 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 f68323c40b..0266d3e57d 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 @@ -243,7 +243,7 @@ private class ButtonProtocolNode( public override fun apply(change: PropertyChange, eventSink: UiEventSink): Unit { val widget = _widget ?: error("detached") - when (change.tag.value) { + when (change.propertyTag.value) { 1 -> widget.text(json.decodeFromJsonElement(serializer_0, change.value)) 2 -> widget.enabled(json.decodeFromJsonElement(serializer_1, change.value)) 3 -> { @@ -254,7 +254,7 @@ private class ButtonProtocolNode( } widget.onClick(onClick) } - else -> mismatchHandler.onUnknownProperty(WidgetTag(12), change.tag) + else -> mismatchHandler.onUnknownProperty(WidgetTag(12), change.propertyTag) } } @@ -425,7 +425,7 @@ internal fun generateProtocolNode( if (properties.isNotEmpty()) { addStatement("val widget = _widget ?: error(%S)", "detached") } - beginControlFlow("when (change.tag.value)") + beginControlFlow("when (change.propertyTag.value)") for (trait in properties) { when (trait) { is ProtocolProperty -> { @@ -500,7 +500,7 @@ internal fun generateProtocolNode( } } .addStatement( - "else -> mismatchHandler.onUnknownProperty(%T(%L), change.tag)", + "else -> mismatchHandler.onUnknownProperty(%T(%L), change.propertyTag)", Protocol.WidgetTag, widget.tag, ) diff --git a/redwood-treehouse-guest/src/jsMain/kotlin/app/cash/redwood/treehouse/ProtocolBridgeJs.kt b/redwood-treehouse-guest/src/jsMain/kotlin/app/cash/redwood/treehouse/ProtocolBridgeJs.kt index 622341f283..f329d3ff81 100644 --- a/redwood-treehouse-guest/src/jsMain/kotlin/app/cash/redwood/treehouse/ProtocolBridgeJs.kt +++ b/redwood-treehouse-guest/src/jsMain/kotlin/app/cash/redwood/treehouse/ProtocolBridgeJs.kt @@ -108,32 +108,42 @@ internal class FastGuestProtocolAdapter( override fun appendPropertyChange( id: Id, - tag: PropertyTag, + widgetTag: WidgetTag, + propertyTag: PropertyTag, serializer: KSerializer, value: T, ) { val id = id - val tag = tag + val widget = widgetTag + val tag = propertyTag val encodedValue = value?.let { json.encodeToDynamic(serializer, it) } - changes.push(js("""["property",{"id":id,"tag":tag,"value":encodedValue}]""")) + changes.push(js("""["property",{"id":id,"widget":widget,"tag":tag,"value":encodedValue}]""")) } override fun appendPropertyChange( id: Id, - tag: PropertyTag, + widgetTag: WidgetTag, + propertyTag: PropertyTag, value: Boolean, ) { val id = id - val tag = tag + val widget = widgetTag + val tag = propertyTag val value = value - changes.push(js("""["property",{"id":id,"tag":tag,"value":value}]""")) + changes.push(js("""["property",{"id":id,"widget":widget,"tag":tag,"value":value}]""")) } - override fun appendPropertyChange(id: Id, tag: PropertyTag, value: UInt) { + override fun appendPropertyChange( + id: Id, + widgetTag: WidgetTag, + propertyTag: PropertyTag, + value: UInt, + ) { val id = id - val tag = tag + val widget = widgetTag + val tag = propertyTag val value = value.toDouble() - changes.push(js("""["property",{"id":id,"tag":tag,"value":value}]""")) + changes.push(js("""["property",{"id":id,"widget":widget,"tag":tag,"value":value}]""")) } override fun appendModifierChange(id: Id, value: Modifier) { diff --git a/redwood-treehouse-host/src/commonTest/kotlin/app/cash/redwood/treehouse/FakeZiplineTreehouseUi.kt b/redwood-treehouse-host/src/commonTest/kotlin/app/cash/redwood/treehouse/FakeZiplineTreehouseUi.kt index 19f350385d..3378fbcbff 100644 --- a/redwood-treehouse-host/src/commonTest/kotlin/app/cash/redwood/treehouse/FakeZiplineTreehouseUi.kt +++ b/redwood-treehouse-host/src/commonTest/kotlin/app/cash/redwood/treehouse/FakeZiplineTreehouseUi.kt @@ -52,9 +52,9 @@ class FakeZiplineTreehouseUi( host.sendChanges( listOf( Create(widgetId, WidgetTag(4)), // Button. - PropertyChange(widgetId, PropertyTag(1), JsonPrimitive(label)), // text. - PropertyChange(widgetId, PropertyTag(2), JsonPrimitive(true)), // onClick. - PropertyChange(widgetId, PropertyTag(3), JsonPrimitive(0u)), // color. + PropertyChange(widgetId, WidgetTag(4), PropertyTag(1), JsonPrimitive(label)), // text. + PropertyChange(widgetId, WidgetTag(4), PropertyTag(2), JsonPrimitive(true)), // onClick. + PropertyChange(widgetId, WidgetTag(4), PropertyTag(3), JsonPrimitive(0u)), // color. ChildrenChange.Add(Id.Root, ChildrenTag.Root, widgetId, 0), ), )