Skip to content

Commit

Permalink
Extract an interface for ProtocolState (#2098)
Browse files Browse the repository at this point in the history
* Extract an interface for ProtocolState

Also begin to convert this interface into a special purpose
service. I'm working towards making it support an alternate
mode for guest code that skips the Changes objects.

* apiDump

* Track generated code change
  • Loading branch information
squarejesse authored Jun 12, 2024
1 parent b5d5fe9 commit 600b51e
Show file tree
Hide file tree
Showing 16 changed files with 411 additions and 176 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import app.cash.redwood.Modifier
import app.cash.redwood.RedwoodCodegenApi
import app.cash.redwood.layout.testing.RedwoodLayoutTestingWidgetFactory
import app.cash.redwood.lazylayout.testing.RedwoodLazyLayoutTestingWidgetFactory
import app.cash.redwood.protocol.guest.DefaultProtocolState
import app.cash.redwood.protocol.guest.guestRedwoodVersion
import app.cash.redwood.protocol.host.ProtocolBridge
import app.cash.redwood.protocol.host.hostRedwoodVersion
Expand Down Expand Up @@ -53,23 +54,24 @@ class DirectChangeListenerTest : AbstractChangeListenerTest() {
}

class ProtocolChangeListenerTest : AbstractChangeListenerTest() {
@OptIn(RedwoodCodegenApi::class)
override fun <T> CoroutineScope.launchComposition(
widgetSystem: TestSchemaWidgetSystem<WidgetValue>,
snapshot: () -> T,
): TestRedwoodComposition<T> {
val composeBridge = TestSchemaProtocolBridge.create(
val state = DefaultProtocolState(
hostVersion = hostRedwoodVersion,
)
val composeBridge = TestSchemaProtocolBridge.create(state)
val widgetBridge = ProtocolBridge(
guestVersion = guestRedwoodVersion,
container = MutableListChildren(),
factory = TestSchemaProtocolFactory(widgetSystem),
eventSink = { throw AssertionError() },
)
state.initChangesSink(widgetBridge)
return TestRedwoodComposition(this, composeBridge.widgetSystem, composeBridge.root) {
composeBridge.getChangesOrNull()?.let { changes ->
widgetBridge.sendChanges(changes)
}
state.emitChanges()
snapshot()
}
}
Expand Down
57 changes: 43 additions & 14 deletions redwood-protocol-guest/api/redwood-protocol-guest.api
Original file line number Diff line number Diff line change
@@ -1,12 +1,33 @@
public final class app/cash/redwood/protocol/guest/DefaultProtocolState : app/cash/redwood/protocol/guest/ProtocolState {
public static final field $stable I
public synthetic fun <init> (Lkotlinx/serialization/json/Json;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (Lkotlinx/serialization/json/Json;Ljava/lang/String;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun addWidget (Lapp/cash/redwood/protocol/guest/ProtocolWidget;)V
public fun appendAdd-11bgaWM (IIII)V
public fun appendCreate-kyz2zXs (II)V
public fun appendModifierChange-z3jyS0k (ILjava/util/List;)V
public fun appendMove-HpxY78w (IIIII)V
public fun appendPropertyChange-DxQz5cw (IILkotlinx/serialization/KSerializer;Ljava/lang/Object;)V
public fun appendPropertyChange-e3iP1vo (IIZ)V
public fun appendRemove-HpxY78w (IIIILjava/util/List;)V
public fun emitChanges ()V
public fun getJson ()Lkotlinx/serialization/json/Json;
public fun getSynthesizeSubtreeRemoval ()Z
public fun getWidget-ou3jOuA (I)Lapp/cash/redwood/protocol/guest/ProtocolWidget;
public fun initChangesSink (Lapp/cash/redwood/protocol/ChangesSink;)V
public fun nextId-0HhLjSo ()I
public fun removeWidget-ou3jOuA (I)V
public final fun takeChanges ()Ljava/util/List;
}

public abstract interface class app/cash/redwood/protocol/guest/ProtocolBridge : app/cash/redwood/protocol/EventSink {
public abstract fun getChangesOrNull ()Ljava/util/List;
public abstract fun getRoot ()Lapp/cash/redwood/widget/Widget$Children;
public abstract fun getWidgetSystem ()Lapp/cash/redwood/widget/WidgetSystem;
}

public abstract interface class app/cash/redwood/protocol/guest/ProtocolBridge$Factory {
public abstract fun create-Bvskwvs (Ljava/lang/String;Lkotlinx/serialization/json/Json;Lapp/cash/redwood/protocol/guest/ProtocolMismatchHandler;)Lapp/cash/redwood/protocol/guest/ProtocolBridge;
public static synthetic fun create-Bvskwvs$default (Lapp/cash/redwood/protocol/guest/ProtocolBridge$Factory;Ljava/lang/String;Lkotlinx/serialization/json/Json;Lapp/cash/redwood/protocol/guest/ProtocolMismatchHandler;ILjava/lang/Object;)Lapp/cash/redwood/protocol/guest/ProtocolBridge;
public abstract fun create (Lapp/cash/redwood/protocol/guest/ProtocolState;Lapp/cash/redwood/protocol/guest/ProtocolMismatchHandler;)Lapp/cash/redwood/protocol/guest/ProtocolBridge;
public static synthetic fun create$default (Lapp/cash/redwood/protocol/guest/ProtocolBridge$Factory;Lapp/cash/redwood/protocol/guest/ProtocolState;Lapp/cash/redwood/protocol/guest/ProtocolMismatchHandler;ILjava/lang/Object;)Lapp/cash/redwood/protocol/guest/ProtocolBridge;
}

public abstract interface class app/cash/redwood/protocol/guest/ProtocolMismatchHandler {
Expand All @@ -20,19 +41,27 @@ public final class app/cash/redwood/protocol/guest/ProtocolMismatchHandler$Compa
}

public final class app/cash/redwood/protocol/guest/ProtocolRedwoodCompositionKt {
public static final fun ProtocolRedwoodComposition-7J1iaxU (Lkotlinx/coroutines/CoroutineScope;Lapp/cash/redwood/protocol/guest/ProtocolBridge;Lapp/cash/redwood/protocol/ChangesSink;ILapp/cash/redwood/ui/OnBackPressedDispatcher;Landroidx/compose/runtime/saveable/SaveableStateRegistry;Lkotlinx/coroutines/flow/StateFlow;)Lapp/cash/redwood/compose/RedwoodComposition;
public static final fun ProtocolRedwoodComposition-C-DY9sE (Lkotlinx/coroutines/CoroutineScope;Lapp/cash/redwood/protocol/guest/ProtocolBridge;ILapp/cash/redwood/ui/OnBackPressedDispatcher;Landroidx/compose/runtime/saveable/SaveableStateRegistry;Lkotlinx/coroutines/flow/StateFlow;Lkotlin/jvm/functions/Function0;)Lapp/cash/redwood/compose/RedwoodComposition;
public static synthetic fun ProtocolRedwoodComposition-C-DY9sE$default (Lkotlinx/coroutines/CoroutineScope;Lapp/cash/redwood/protocol/guest/ProtocolBridge;ILapp/cash/redwood/ui/OnBackPressedDispatcher;Landroidx/compose/runtime/saveable/SaveableStateRegistry;Lkotlinx/coroutines/flow/StateFlow;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)Lapp/cash/redwood/compose/RedwoodComposition;
}

public final class app/cash/redwood/protocol/guest/ProtocolState {
public static final field $stable I
public synthetic fun <init> (Ljava/lang/String;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun addWidget (Lapp/cash/redwood/protocol/guest/ProtocolWidget;)V
public final fun append (Lapp/cash/redwood/protocol/Change;)V
public final fun getChangesOrNull ()Ljava/util/List;
public final fun getSynthesizeSubtreeRemoval ()Z
public final fun getWidget-ou3jOuA (I)Lapp/cash/redwood/protocol/guest/ProtocolWidget;
public final fun nextId-0HhLjSo ()I
public final fun removeWidget-ou3jOuA (I)V
public abstract interface class app/cash/redwood/protocol/guest/ProtocolState {
public abstract fun addWidget (Lapp/cash/redwood/protocol/guest/ProtocolWidget;)V
public abstract fun appendAdd-11bgaWM (IIII)V
public abstract fun appendCreate-kyz2zXs (II)V
public abstract fun appendModifierChange-z3jyS0k (ILjava/util/List;)V
public abstract fun appendMove-HpxY78w (IIIII)V
public abstract fun appendPropertyChange-DxQz5cw (IILkotlinx/serialization/KSerializer;Ljava/lang/Object;)V
public abstract fun appendPropertyChange-e3iP1vo (IIZ)V
public abstract fun appendRemove-HpxY78w (IIIILjava/util/List;)V
public static synthetic fun appendRemove-HpxY78w$default (Lapp/cash/redwood/protocol/guest/ProtocolState;IIIILjava/util/List;ILjava/lang/Object;)V
public abstract fun emitChanges ()V
public abstract fun getJson ()Lkotlinx/serialization/json/Json;
public abstract fun getSynthesizeSubtreeRemoval ()Z
public abstract fun getWidget-ou3jOuA (I)Lapp/cash/redwood/protocol/guest/ProtocolWidget;
public abstract fun initChangesSink (Lapp/cash/redwood/protocol/ChangesSink;)V
public abstract fun nextId-0HhLjSo ()I
public abstract fun removeWidget-ou3jOuA (I)V
}

public abstract interface class app/cash/redwood/protocol/guest/ProtocolWidget : app/cash/redwood/widget/Widget {
Expand Down
Loading

0 comments on commit 600b51e

Please sign in to comment.