Skip to content

Commit 5f8ca01

Browse files
authored
Revert "Defer serializing event args to JSON (#2218)" (#2239)
This reverts commit 4010e12.
1 parent c9830cc commit 5f8ca01

File tree

15 files changed

+73
-185
lines changed

15 files changed

+73
-185
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ New:
88
- Introduce a `LoadingStrategy` interface to manage `LazyList` preloading.
99

1010
Changed:
11-
- In Treehouse, events from the UI are now serialized on a background thread. This means that there is both a delay and a thread change between when a UI binding sends an event and when that object is converted to JSON. All arguments to events must not be mutable and support property reads on any thread. Best practice is for all event arguments to be completely immutable.
1211
- `ProtocolFactory` interface is now sealed as arbitrary subtypes were never supported. Only schema-generated subtypes should be used.
1312

1413
Fixed:

redwood-protocol-host/api/redwood-protocol-host.api

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ public abstract interface class app/cash/redwood/protocol/host/GeneratedProtocol
55
}
66

77
public final class app/cash/redwood/protocol/host/HostProtocolAdapter : app/cash/redwood/protocol/ChangesSink {
8-
public synthetic fun <init> (Ljava/lang/String;Lapp/cash/redwood/widget/Widget$Children;Lapp/cash/redwood/protocol/host/ProtocolFactory;Lapp/cash/redwood/protocol/host/UiEventSink;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
8+
public synthetic fun <init> (Ljava/lang/String;Lapp/cash/redwood/widget/Widget$Children;Lapp/cash/redwood/protocol/host/ProtocolFactory;Lapp/cash/redwood/protocol/EventSink;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
99
public final fun close ()V
1010
public fun sendChanges (Ljava/util/List;)V
1111
}
@@ -35,7 +35,7 @@ public final class app/cash/redwood/protocol/host/ProtocolMismatchHandler$Compan
3535

3636
public abstract class app/cash/redwood/protocol/host/ProtocolNode {
3737
public synthetic fun <init> (IILkotlin/jvm/internal/DefaultConstructorMarker;)V
38-
public abstract fun apply (Lapp/cash/redwood/protocol/PropertyChange;Lapp/cash/redwood/protocol/host/UiEventSink;)V
38+
public abstract fun apply (Lapp/cash/redwood/protocol/PropertyChange;Lapp/cash/redwood/protocol/EventSink;)V
3939
public abstract fun children-dBpC-2Y (I)Lapp/cash/redwood/protocol/host/ProtocolChildren;
4040
public abstract fun detach ()V
4141
public final fun getId-0HhLjSo ()I
@@ -45,23 +45,6 @@ public abstract class app/cash/redwood/protocol/host/ProtocolNode {
4545
public abstract fun visitIds (Lkotlin/jvm/functions/Function1;)V
4646
}
4747

48-
public final class app/cash/redwood/protocol/host/UiEvent {
49-
public synthetic fun <init> (IILjava/util/List;Ljava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
50-
public synthetic fun <init> (IILjava/util/List;Ljava/util/List;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
51-
public fun equals (Ljava/lang/Object;)Z
52-
public final fun getArgs ()Ljava/util/List;
53-
public final fun getId-0HhLjSo ()I
54-
public final fun getSerializationStrategies ()Ljava/util/List;
55-
public final fun getTag-RNF89mI ()I
56-
public fun hashCode ()I
57-
public final fun toProtocol (Lkotlinx/serialization/json/Json;)Lapp/cash/redwood/protocol/Event;
58-
public fun toString ()Ljava/lang/String;
59-
}
60-
61-
public abstract interface class app/cash/redwood/protocol/host/UiEventSink {
62-
public abstract fun sendEvent (Lapp/cash/redwood/protocol/host/UiEvent;)V
63-
}
64-
6548
public final class app/cash/redwood/protocol/host/VersionKt {
6649
public static final fun getHostRedwoodVersion ()Ljava/lang/String;
6750
}

redwood-protocol-host/api/redwood-protocol-host.klib.api

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
// - Show declarations: true
77

88
// Library unique name: <app.cash.redwood:redwood-protocol-host>
9-
abstract fun interface app.cash.redwood.protocol.host/UiEventSink { // app.cash.redwood.protocol.host/UiEventSink|null[0]
10-
abstract fun sendEvent(app.cash.redwood.protocol.host/UiEvent) // app.cash.redwood.protocol.host/UiEventSink.sendEvent|sendEvent(app.cash.redwood.protocol.host.UiEvent){}[0]
11-
}
12-
139
abstract interface <#A: kotlin/Any> app.cash.redwood.protocol.host/GeneratedProtocolFactory : app.cash.redwood.protocol.host/ProtocolFactory<#A> { // app.cash.redwood.protocol.host/GeneratedProtocolFactory|null[0]
1410
abstract fun createModifier(app.cash.redwood.protocol/ModifierElement): app.cash.redwood/Modifier // app.cash.redwood.protocol.host/GeneratedProtocolFactory.createModifier|createModifier(app.cash.redwood.protocol.ModifierElement){}[0]
1511
abstract fun createNode(app.cash.redwood.protocol/Id, app.cash.redwood.protocol/WidgetTag): app.cash.redwood.protocol.host/ProtocolNode<#A>? // app.cash.redwood.protocol.host/GeneratedProtocolFactory.createNode|createNode(app.cash.redwood.protocol.Id;app.cash.redwood.protocol.WidgetTag){}[0]
@@ -43,15 +39,15 @@ abstract class <#A: kotlin/Any> app.cash.redwood.protocol.host/ProtocolNode { //
4339
final val widgetTag // app.cash.redwood.protocol.host/ProtocolNode.widgetTag|{}widgetTag[0]
4440
final fun <get-widgetTag>(): app.cash.redwood.protocol/WidgetTag // app.cash.redwood.protocol.host/ProtocolNode.widgetTag.<get-widgetTag>|<get-widgetTag>(){}[0]
4541

46-
abstract fun apply(app.cash.redwood.protocol/PropertyChange, app.cash.redwood.protocol.host/UiEventSink) // app.cash.redwood.protocol.host/ProtocolNode.apply|apply(app.cash.redwood.protocol.PropertyChange;app.cash.redwood.protocol.host.UiEventSink){}[0]
42+
abstract fun apply(app.cash.redwood.protocol/PropertyChange, app.cash.redwood.protocol/EventSink) // app.cash.redwood.protocol.host/ProtocolNode.apply|apply(app.cash.redwood.protocol.PropertyChange;app.cash.redwood.protocol.EventSink){}[0]
4743
abstract fun children(app.cash.redwood.protocol/ChildrenTag): app.cash.redwood.protocol.host/ProtocolChildren<#A>? // app.cash.redwood.protocol.host/ProtocolNode.children|children(app.cash.redwood.protocol.ChildrenTag){}[0]
4844
abstract fun detach() // app.cash.redwood.protocol.host/ProtocolNode.detach|detach(){}[0]
4945
abstract fun visitIds(kotlin/Function1<app.cash.redwood.protocol/Id, kotlin/Unit>) // app.cash.redwood.protocol.host/ProtocolNode.visitIds|visitIds(kotlin.Function1<app.cash.redwood.protocol.Id,kotlin.Unit>){}[0]
5046
final fun updateModifier(app.cash.redwood/Modifier) // app.cash.redwood.protocol.host/ProtocolNode.updateModifier|updateModifier(app.cash.redwood.Modifier){}[0]
5147
}
5248

5349
final class <#A: kotlin/Any> app.cash.redwood.protocol.host/HostProtocolAdapter : app.cash.redwood.protocol/ChangesSink { // app.cash.redwood.protocol.host/HostProtocolAdapter|null[0]
54-
constructor <init>(app.cash.redwood.protocol/RedwoodVersion, app.cash.redwood.widget/Widget.Children<#A>, app.cash.redwood.protocol.host/ProtocolFactory<#A>, app.cash.redwood.protocol.host/UiEventSink) // app.cash.redwood.protocol.host/HostProtocolAdapter.<init>|<init>(app.cash.redwood.protocol.RedwoodVersion;app.cash.redwood.widget.Widget.Children<1:0>;app.cash.redwood.protocol.host.ProtocolFactory<1:0>;app.cash.redwood.protocol.host.UiEventSink){}[0]
50+
constructor <init>(app.cash.redwood.protocol/RedwoodVersion, app.cash.redwood.widget/Widget.Children<#A>, app.cash.redwood.protocol.host/ProtocolFactory<#A>, app.cash.redwood.protocol/EventSink) // app.cash.redwood.protocol.host/HostProtocolAdapter.<init>|<init>(app.cash.redwood.protocol.RedwoodVersion;app.cash.redwood.widget.Widget.Children<1:0>;app.cash.redwood.protocol.host.ProtocolFactory<1:0>;app.cash.redwood.protocol.EventSink){}[0]
5551

5652
final fun close() // app.cash.redwood.protocol.host/HostProtocolAdapter.close|close(){}[0]
5753
final fun sendChanges(kotlin.collections/List<app.cash.redwood.protocol/Change>) // app.cash.redwood.protocol.host/HostProtocolAdapter.sendChanges|sendChanges(kotlin.collections.List<app.cash.redwood.protocol.Change>){}[0]
@@ -67,23 +63,5 @@ final class <#A: kotlin/Any> app.cash.redwood.protocol.host/ProtocolChildren { /
6763
final fun visitIds(kotlin/Function1<app.cash.redwood.protocol/Id, kotlin/Unit>) // app.cash.redwood.protocol.host/ProtocolChildren.visitIds|visitIds(kotlin.Function1<app.cash.redwood.protocol.Id,kotlin.Unit>){}[0]
6864
}
6965

70-
final class app.cash.redwood.protocol.host/UiEvent { // app.cash.redwood.protocol.host/UiEvent|null[0]
71-
constructor <init>(app.cash.redwood.protocol/Id, app.cash.redwood.protocol/EventTag, kotlin.collections/List<kotlin/Any?> = ..., kotlin.collections/List<kotlinx.serialization/SerializationStrategy<kotlin/Any?>> = ...) // app.cash.redwood.protocol.host/UiEvent.<init>|<init>(app.cash.redwood.protocol.Id;app.cash.redwood.protocol.EventTag;kotlin.collections.List<kotlin.Any?>;kotlin.collections.List<kotlinx.serialization.SerializationStrategy<kotlin.Any?>>){}[0]
72-
73-
final val args // app.cash.redwood.protocol.host/UiEvent.args|{}args[0]
74-
final fun <get-args>(): kotlin.collections/List<kotlin/Any?> // app.cash.redwood.protocol.host/UiEvent.args.<get-args>|<get-args>(){}[0]
75-
final val id // app.cash.redwood.protocol.host/UiEvent.id|{}id[0]
76-
final fun <get-id>(): app.cash.redwood.protocol/Id // app.cash.redwood.protocol.host/UiEvent.id.<get-id>|<get-id>(){}[0]
77-
final val serializationStrategies // app.cash.redwood.protocol.host/UiEvent.serializationStrategies|{}serializationStrategies[0]
78-
final fun <get-serializationStrategies>(): kotlin.collections/List<kotlinx.serialization/SerializationStrategy<kotlin/Any?>> // app.cash.redwood.protocol.host/UiEvent.serializationStrategies.<get-serializationStrategies>|<get-serializationStrategies>(){}[0]
79-
final val tag // app.cash.redwood.protocol.host/UiEvent.tag|{}tag[0]
80-
final fun <get-tag>(): app.cash.redwood.protocol/EventTag // app.cash.redwood.protocol.host/UiEvent.tag.<get-tag>|<get-tag>(){}[0]
81-
82-
final fun equals(kotlin/Any?): kotlin/Boolean // app.cash.redwood.protocol.host/UiEvent.equals|equals(kotlin.Any?){}[0]
83-
final fun hashCode(): kotlin/Int // app.cash.redwood.protocol.host/UiEvent.hashCode|hashCode(){}[0]
84-
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]
85-
final fun toString(): kotlin/String // app.cash.redwood.protocol.host/UiEvent.toString|toString(){}[0]
86-
}
87-
8866
final val app.cash.redwood.protocol.host/hostRedwoodVersion // app.cash.redwood.protocol.host/hostRedwoodVersion|{}hostRedwoodVersion[0]
8967
final fun <get-hostRedwoodVersion>(): app.cash.redwood.protocol/RedwoodVersion // app.cash.redwood.protocol.host/hostRedwoodVersion.<get-hostRedwoodVersion>|<get-hostRedwoodVersion>(){}[0]

redwood-protocol-host/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ redwoodBuild {
66
}
77

88
apply plugin: 'com.github.gmazzo.buildconfig'
9-
apply plugin: 'dev.drewhamilton.poko'
109

1110
kotlin {
1211
sourceSets {

redwood-protocol-host/src/commonMain/kotlin/app/cash/redwood/protocol/host/HostProtocolAdapter.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import app.cash.redwood.protocol.ChildrenChange.Move
2525
import app.cash.redwood.protocol.ChildrenChange.Remove
2626
import app.cash.redwood.protocol.ChildrenTag
2727
import app.cash.redwood.protocol.Create
28+
import app.cash.redwood.protocol.EventSink
2829
import app.cash.redwood.protocol.Id
2930
import app.cash.redwood.protocol.ModifierChange
3031
import app.cash.redwood.protocol.PropertyChange
@@ -49,7 +50,7 @@ public class HostProtocolAdapter<W : Any>(
4950
guestVersion: RedwoodVersion,
5051
container: Widget.Children<W>,
5152
factory: ProtocolFactory<W>,
52-
private val eventSink: UiEventSink,
53+
private val eventSink: EventSink,
5354
) : ChangesSink {
5455
private val factory = requireNotNull(factory as? GeneratedProtocolFactory<W>) {
5556
"Factory ${factory::class} was not generated by Redwood or is out of date"
@@ -377,7 +378,7 @@ private class RootProtocolNode<W : Any>(
377378
Widget<W> {
378379
private val children = ProtocolChildren(children)
379380

380-
override fun apply(change: PropertyChange, eventSink: UiEventSink) {
381+
override fun apply(change: PropertyChange, eventSink: EventSink) {
381382
throw AssertionError("unexpected: $change")
382383
}
383384

redwood-protocol-host/src/commonMain/kotlin/app/cash/redwood/protocol/host/ProtocolNode.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package app.cash.redwood.protocol.host
1818
import app.cash.redwood.Modifier
1919
import app.cash.redwood.RedwoodCodegenApi
2020
import app.cash.redwood.protocol.ChildrenTag
21+
import app.cash.redwood.protocol.EventSink
2122
import app.cash.redwood.protocol.Id
2223
import app.cash.redwood.protocol.PropertyChange
2324
import app.cash.redwood.protocol.WidgetTag
@@ -47,7 +48,7 @@ public abstract class ProtocolNode<W : Any>(
4748
/** Assigned when the node is added to the pool. */
4849
internal var shapeHash = 0L
4950

50-
public abstract fun apply(change: PropertyChange, eventSink: UiEventSink)
51+
public abstract fun apply(change: PropertyChange, eventSink: EventSink)
5152

5253
public fun updateModifier(modifier: Modifier) {
5354
widget.modifier = modifier

redwood-protocol-host/src/commonMain/kotlin/app/cash/redwood/protocol/host/UiEvent.kt

Lines changed: 0 additions & 59 deletions
This file was deleted.

redwood-protocol-host/src/commonTest/kotlin/app/cash/redwood/protocol/host/ChildrenNodeIndexTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package app.cash.redwood.protocol.host
1818
import app.cash.redwood.Modifier
1919
import app.cash.redwood.RedwoodCodegenApi
2020
import app.cash.redwood.protocol.ChildrenTag
21+
import app.cash.redwood.protocol.EventSink
2122
import app.cash.redwood.protocol.Id
2223
import app.cash.redwood.protocol.PropertyChange
2324
import app.cash.redwood.protocol.WidgetTag
@@ -127,7 +128,7 @@ class ChildrenNodeIndexTest {
127128

128129
@OptIn(RedwoodCodegenApi::class)
129130
private class WidgetNode(override val widget: StringWidget) : ProtocolNode<String>(Id(1), WidgetTag(1)) {
130-
override fun apply(change: PropertyChange, eventSink: UiEventSink) {
131+
override fun apply(change: PropertyChange, eventSink: EventSink) {
131132
throw UnsupportedOperationException()
132133
}
133134

redwood-protocol-host/src/commonTest/kotlin/app/cash/redwood/protocol/host/ProtocolFactoryTest.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import app.cash.redwood.layout.testing.RedwoodLayoutTestingWidgetFactory
2121
import app.cash.redwood.lazylayout.testing.RedwoodLazyLayoutTestingWidgetFactory
2222
import app.cash.redwood.protocol.ChildrenTag
2323
import app.cash.redwood.protocol.Event
24+
import app.cash.redwood.protocol.EventSink
2425
import app.cash.redwood.protocol.EventTag
2526
import app.cash.redwood.protocol.Id
2627
import app.cash.redwood.protocol.ModifierElement
@@ -257,7 +258,7 @@ class ProtocolFactoryTest {
257258
)
258259
val textInput = factory.createNode(Id(1), WidgetTag(5))!!
259260

260-
val throwingEventSink = UiEventSink { error(it) }
261+
val throwingEventSink = EventSink { error(it) }
261262
textInput.apply(PropertyChange(Id(1), PropertyTag(2), JsonPrimitive("PT10S")), throwingEventSink)
262263

263264
assertThat((textInput.widget.value as TextInputValue).customType).isEqualTo(10.seconds)
@@ -274,7 +275,7 @@ class ProtocolFactoryTest {
274275
val button = factory.createNode(Id(1), WidgetTag(4))!!
275276

276277
val change = PropertyChange(Id(1), PropertyTag(345432))
277-
val eventSink = UiEventSink { throw UnsupportedOperationException() }
278+
val eventSink = EventSink { throw UnsupportedOperationException() }
278279
val t = assertFailsWith<IllegalArgumentException> {
279280
button.apply(change, eventSink)
280281
}
@@ -314,12 +315,12 @@ class ProtocolFactoryTest {
314315
)
315316
val textInput = factory.createNode(Id(1), WidgetTag(5))!!
316317

317-
val eventSink = RecordingUiEventSink()
318+
val eventSink = RecordingEventSink()
318319
textInput.apply(PropertyChange(Id(1), PropertyTag(4), JsonPrimitive(true)), eventSink)
319320

320321
(textInput.widget.value as TextInputValue).onChangeCustomType!!.invoke(10.seconds)
321322

322-
assertThat(eventSink.events.single().toProtocol(json))
323+
assertThat(eventSink.events.single())
323324
.isEqualTo(Event(Id(1), EventTag(4), listOf(JsonPrimitive("PT10S"))))
324325
}
325326
}
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@
1515
*/
1616
package app.cash.redwood.protocol.host
1717

18-
class RecordingUiEventSink : UiEventSink {
19-
val events = mutableListOf<UiEvent>()
18+
import app.cash.redwood.protocol.Event
19+
import app.cash.redwood.protocol.EventSink
2020

21-
override fun sendEvent(uiEvent: UiEvent) {
22-
events += uiEvent
21+
class RecordingEventSink : EventSink {
22+
val events = mutableListOf<Event>()
23+
24+
override fun sendEvent(event: Event) {
25+
events += event
2326
}
2427
}

0 commit comments

Comments
 (0)