diff --git a/benchmarks/performance-poetry/complex-poetry/src/androidTest/java/com/squareup/benchmarks/performance/complex/poetry/RenderPassTest.kt b/benchmarks/performance-poetry/complex-poetry/src/androidTest/java/com/squareup/benchmarks/performance/complex/poetry/RenderPassTest.kt index 9f566a7dc3..0cdc9ef554 100644 --- a/benchmarks/performance-poetry/complex-poetry/src/androidTest/java/com/squareup/benchmarks/performance/complex/poetry/RenderPassTest.kt +++ b/benchmarks/performance-poetry/complex-poetry/src/androidTest/java/com/squareup/benchmarks/performance/complex/poetry/RenderPassTest.kt @@ -227,7 +227,7 @@ class RenderPassTest { useHighFrequencyRange = true, simultaneousActions = 0, baselineExpectation = RenderExpectation( - totalPasses = 181..181, + totalPasses = 150..150, freshRenderedNodes = 213..213, staleRenderedNodes = 2350..2350 ), diff --git a/samples/compose-samples/src/main/java/com/squareup/sample/compose/hellocomposeworkflow/ComposeWorkflow.kt b/samples/compose-samples/src/main/java/com/squareup/sample/compose/hellocomposeworkflow/ComposeWorkflow.kt index da39ae62f8..4cb98d2e57 100644 --- a/samples/compose-samples/src/main/java/com/squareup/sample/compose/hellocomposeworkflow/ComposeWorkflow.kt +++ b/samples/compose-samples/src/main/java/com/squareup/sample/compose/hellocomposeworkflow/ComposeWorkflow.kt @@ -5,6 +5,8 @@ import com.squareup.workflow1.RenderContext import com.squareup.workflow1.Sink import com.squareup.workflow1.StatefulWorkflow import com.squareup.workflow1.Workflow +import com.squareup.workflow1.WorkflowIdentifier +import com.squareup.workflow1.computeIdentifier import com.squareup.workflow1.ui.ViewEnvironment import com.squareup.workflow1.ui.WorkflowUiExperimentalApi import com.squareup.workflow1.ui.compose.ComposeScreen @@ -48,6 +50,8 @@ abstract class ComposeWorkflow : override fun asStatefulWorkflow(): StatefulWorkflow = ComposeWorkflowImpl(this) + + override val identifier: WorkflowIdentifier = computeIdentifier() } /** diff --git a/workflow-core/api/workflow-core.api b/workflow-core/api/workflow-core.api index 5a896de3ed..8fa38e91e8 100644 --- a/workflow-core/api/workflow-core.api +++ b/workflow-core/api/workflow-core.api @@ -118,6 +118,7 @@ public final class com/squareup/workflow1/Snapshots { public abstract class com/squareup/workflow1/StatefulWorkflow : com/squareup/workflow1/Workflow { public fun ()V public final fun asStatefulWorkflow ()Lcom/squareup/workflow1/StatefulWorkflow; + public fun getIdentifier ()Lcom/squareup/workflow1/WorkflowIdentifier; public abstract fun initialState (Ljava/lang/Object;Lcom/squareup/workflow1/Snapshot;)Ljava/lang/Object; public fun onPropsChanged (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun render (Ljava/lang/Object;Ljava/lang/Object;Lcom/squareup/workflow1/StatefulWorkflow$RenderContext;)Ljava/lang/Object; @@ -144,6 +145,7 @@ public final class com/squareup/workflow1/StatefulWorkflow$RenderContext : com/s public abstract class com/squareup/workflow1/StatelessWorkflow : com/squareup/workflow1/Workflow { public fun ()V public final fun asStatefulWorkflow ()Lcom/squareup/workflow1/StatefulWorkflow; + public fun getIdentifier ()Lcom/squareup/workflow1/WorkflowIdentifier; public abstract fun render (Ljava/lang/Object;Lcom/squareup/workflow1/StatelessWorkflow$RenderContext;)Ljava/lang/Object; } @@ -191,6 +193,7 @@ public final class com/squareup/workflow1/Worker$DefaultImpls { public abstract interface class com/squareup/workflow1/Workflow { public static final field Companion Lcom/squareup/workflow1/Workflow$Companion; public abstract fun asStatefulWorkflow ()Lcom/squareup/workflow1/StatefulWorkflow; + public abstract fun getIdentifier ()Lcom/squareup/workflow1/WorkflowIdentifier; } public final class com/squareup/workflow1/Workflow$Companion { @@ -283,8 +286,8 @@ public final class com/squareup/workflow1/Workflows { public static synthetic fun action$default (Lcom/squareup/workflow1/StatelessWorkflow;Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lcom/squareup/workflow1/WorkflowAction; public static synthetic fun action$default (Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lcom/squareup/workflow1/WorkflowAction; public static final fun applyTo (Lcom/squareup/workflow1/WorkflowAction;Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair; + public static final fun computeIdentifier (Lcom/squareup/workflow1/Workflow;)Lcom/squareup/workflow1/WorkflowIdentifier; public static final fun contraMap (Lcom/squareup/workflow1/Sink;Lkotlin/jvm/functions/Function1;)Lcom/squareup/workflow1/Sink; - public static final fun getIdentifier (Lcom/squareup/workflow1/Workflow;)Lcom/squareup/workflow1/WorkflowIdentifier; public static final fun mapRendering (Lcom/squareup/workflow1/Workflow;Lkotlin/jvm/functions/Function1;)Lcom/squareup/workflow1/Workflow; public static final fun renderChild (Lcom/squareup/workflow1/BaseRenderContext;Lcom/squareup/workflow1/Workflow;Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object; public static final fun renderChild (Lcom/squareup/workflow1/BaseRenderContext;Lcom/squareup/workflow1/Workflow;Ljava/lang/String;)Ljava/lang/Object; diff --git a/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/ImpostorWorkflow.kt b/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/ImpostorWorkflow.kt index 4e75c8f7dd..c11abaf4d7 100644 --- a/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/ImpostorWorkflow.kt +++ b/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/ImpostorWorkflow.kt @@ -18,7 +18,7 @@ import kotlin.jvm.JvmName public interface ImpostorWorkflow { /** * The [WorkflowIdentifier] of another workflow to be combined with the identifier of this - * workflow, as obtained by [Workflow.identifier]. + * workflow, as obtained by [Workflow.computeIdentifier]. * * For workflows that implement operators, this should be the identifier of the upstream * [Workflow] that this workflow wraps. diff --git a/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/StatefulWorkflow.kt b/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/StatefulWorkflow.kt index 031235ff4c..f961448996 100644 --- a/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/StatefulWorkflow.kt +++ b/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/StatefulWorkflow.kt @@ -129,6 +129,10 @@ public abstract class StatefulWorkflow< context: RenderContext ): RenderingT + override val identifier: WorkflowIdentifier by lazy { + computeIdentifier() + } + /** * Called whenever the state changes to generate a new [Snapshot] of the state. * diff --git a/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/StatelessWorkflow.kt b/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/StatelessWorkflow.kt index f6545524e2..e052e34519 100644 --- a/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/StatelessWorkflow.kt +++ b/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/StatelessWorkflow.kt @@ -57,6 +57,10 @@ public abstract class StatelessWorkflow context: RenderContext ): RenderingT + override val identifier: WorkflowIdentifier by lazy { + computeIdentifier() + } + /** * Satisfies the [Workflow] interface by wrapping `this` in a [StatefulWorkflow] with `Unit` * state. diff --git a/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/Workflow.kt b/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/Workflow.kt index ce2aaf685d..f477f8e992 100644 --- a/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/Workflow.kt +++ b/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/Workflow.kt @@ -104,6 +104,8 @@ public interface Workflow { */ public fun asStatefulWorkflow(): StatefulWorkflow + public val identifier: WorkflowIdentifier + /** * Empty companion serves as a hook point to allow us to create `Workflow.foo` * extension methods elsewhere. @@ -120,7 +122,7 @@ Workflow.mapRendering( transform: (FromRenderingT) -> ToRenderingT ): Workflow = object : StatelessWorkflow(), ImpostorWorkflow { - override val realIdentifier: WorkflowIdentifier get() = this@mapRendering.identifier + override val realIdentifier: WorkflowIdentifier = this@mapRendering.identifier override fun render( renderProps: PropsT, diff --git a/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/WorkflowIdentifier.kt b/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/WorkflowIdentifier.kt index a155834531..f1048c0046 100644 --- a/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/WorkflowIdentifier.kt +++ b/workflow-core/src/commonMain/kotlin/com/squareup/workflow1/WorkflowIdentifier.kt @@ -146,15 +146,14 @@ public class WorkflowIdentifier internal constructor( /** * The [WorkflowIdentifier] that identifies this [Workflow]. */ -public val Workflow<*, *, *>.identifier: WorkflowIdentifier - get() { - val maybeImpostor = this as? ImpostorWorkflow - return WorkflowIdentifier( - type = Snapshottable(this::class), - proxiedIdentifier = maybeImpostor?.realIdentifier, - description = maybeImpostor?.let { it::describeRealIdentifier } - ) - } +public fun Workflow<*, *, *>.computeIdentifier(): WorkflowIdentifier { + val maybeImpostor = this as? ImpostorWorkflow + return WorkflowIdentifier( + type = Snapshottable(this::class), + proxiedIdentifier = maybeImpostor?.realIdentifier, + description = maybeImpostor?.let { it::describeRealIdentifier } + ) +} /** * Creates a [WorkflowIdentifier] that is not capable of being snapshotted and will cause any diff --git a/workflow-core/src/commonTest/kotlin/com/squareup/workflow1/WorkflowIdentifierTest.kt b/workflow-core/src/commonTest/kotlin/com/squareup/workflow1/WorkflowIdentifierTest.kt index b3bb5b7fd3..947c61cf10 100644 --- a/workflow-core/src/commonTest/kotlin/com/squareup/workflow1/WorkflowIdentifierTest.kt +++ b/workflow-core/src/commonTest/kotlin/com/squareup/workflow1/WorkflowIdentifierTest.kt @@ -172,17 +172,22 @@ internal class WorkflowIdentifierTest { public object TestWorkflow1 : Workflow { override fun asStatefulWorkflow(): StatefulWorkflow = throw NotImplementedError() + + override val identifier: WorkflowIdentifier = computeIdentifier() } public object TestWorkflow2 : Workflow { override fun asStatefulWorkflow(): StatefulWorkflow = throw NotImplementedError() + + override val identifier: WorkflowIdentifier = computeIdentifier() } public class TestImpostor1( private val proxied: Workflow<*, *, *> ) : Workflow, ImpostorWorkflow { override val realIdentifier: WorkflowIdentifier = proxied.identifier + override val identifier: WorkflowIdentifier = computeIdentifier() override fun describeRealIdentifier(): String = "TestImpostor1(${WorkflowIdentifierTypeNamer.uniqueName(proxied::class)})" override fun asStatefulWorkflow(): StatefulWorkflow = @@ -193,6 +198,7 @@ internal class WorkflowIdentifierTest { proxied: Workflow<*, *, *> ) : Workflow, ImpostorWorkflow { override val realIdentifier: WorkflowIdentifier = proxied.identifier + override val identifier: WorkflowIdentifier = computeIdentifier() override fun asStatefulWorkflow(): StatefulWorkflow = throw NotImplementedError() } @@ -201,6 +207,7 @@ internal class WorkflowIdentifierTest { type: KType ) : Workflow, ImpostorWorkflow { override val realIdentifier: WorkflowIdentifier = unsnapshottableIdentifier(type) + override val identifier: WorkflowIdentifier = computeIdentifier() override fun asStatefulWorkflow(): StatefulWorkflow = throw NotImplementedError() } diff --git a/workflow-core/src/iosTest/kotlin/com/squareup/workflow1/NativeWorkflowIdentifierTest.kt b/workflow-core/src/iosTest/kotlin/com/squareup/workflow1/NativeWorkflowIdentifierTest.kt index fdc5f2c882..aeae047852 100644 --- a/workflow-core/src/iosTest/kotlin/com/squareup/workflow1/NativeWorkflowIdentifierTest.kt +++ b/workflow-core/src/iosTest/kotlin/com/squareup/workflow1/NativeWorkflowIdentifierTest.kt @@ -21,6 +21,7 @@ class NativeWorkflowIdentifierTest { fun `impostor identifier toString uses full chain when describeRealIdentifier returns null`() { class TestImpostor : Workflow, ImpostorWorkflow { override val realIdentifier: WorkflowIdentifier = TestWorkflow1.identifier + override val identifier: WorkflowIdentifier = computeIdentifier() override fun describeRealIdentifier(): String? = null override fun asStatefulWorkflow(): StatefulWorkflow = diff --git a/workflow-core/src/jsTest/kotlin/com.squareup.workflow1/JsWorkflowIdentifierTest.kt b/workflow-core/src/jsTest/kotlin/com.squareup.workflow1/JsWorkflowIdentifierTest.kt index 106ca79059..ee200229ec 100644 --- a/workflow-core/src/jsTest/kotlin/com.squareup.workflow1/JsWorkflowIdentifierTest.kt +++ b/workflow-core/src/jsTest/kotlin/com.squareup.workflow1/JsWorkflowIdentifierTest.kt @@ -26,6 +26,7 @@ internal class JsWorkflowIdentifierTest { fun impostor_identifier_toString_uses_full_chain_when_describeRealIdentifier_returns_null() { class TestImpostor : Workflow, ImpostorWorkflow { override val realIdentifier: WorkflowIdentifier = TestWorkflow1.identifier + override val identifier: WorkflowIdentifier = computeIdentifier() override fun describeRealIdentifier(): String? = null override fun asStatefulWorkflow(): StatefulWorkflow = diff --git a/workflow-core/src/jsTest/kotlin/com.squareup.workflow1/mocks.workflows1/JsMockWorkflows.kt b/workflow-core/src/jsTest/kotlin/com.squareup.workflow1/mocks.workflows1/JsMockWorkflows.kt index ecf938806e..d2f8f72d7e 100644 --- a/workflow-core/src/jsTest/kotlin/com.squareup.workflow1/mocks.workflows1/JsMockWorkflows.kt +++ b/workflow-core/src/jsTest/kotlin/com.squareup.workflow1/mocks.workflows1/JsMockWorkflows.kt @@ -2,13 +2,19 @@ package com.squareup.workflow1.mocks.workflows1 import com.squareup.workflow1.StatefulWorkflow import com.squareup.workflow1.Workflow +import com.squareup.workflow1.WorkflowIdentifier +import com.squareup.workflow1.computeIdentifier public class JsMockWorkflow1 : Workflow { override fun asStatefulWorkflow(): StatefulWorkflow = throw NotImplementedError() + + override val identifier: WorkflowIdentifier = computeIdentifier() } public class JsMockWorkflow2 : Workflow { override fun asStatefulWorkflow(): StatefulWorkflow = throw NotImplementedError() + + override val identifier: WorkflowIdentifier = computeIdentifier() } diff --git a/workflow-core/src/jsTest/kotlin/com.squareup.workflow1/mocks.workflows2/JsMockWorkflow1.kt b/workflow-core/src/jsTest/kotlin/com.squareup.workflow1/mocks.workflows2/JsMockWorkflow1.kt index 841db956e7..3feeb719c9 100644 --- a/workflow-core/src/jsTest/kotlin/com.squareup.workflow1/mocks.workflows2/JsMockWorkflow1.kt +++ b/workflow-core/src/jsTest/kotlin/com.squareup.workflow1/mocks.workflows2/JsMockWorkflow1.kt @@ -2,10 +2,14 @@ package com.squareup.workflow1.mocks.workflows2 import com.squareup.workflow1.StatefulWorkflow import com.squareup.workflow1.Workflow +import com.squareup.workflow1.WorkflowIdentifier +import com.squareup.workflow1.computeIdentifier // This is purposely duplicated to be like com.squareup.workflow1.mocks.workflows1.JsMockWorkflow1, // but with a slightly different Output. public class JsMockWorkflow1 : Workflow { override fun asStatefulWorkflow(): StatefulWorkflow = throw NotImplementedError() + + override val identifier: WorkflowIdentifier = computeIdentifier() } diff --git a/workflow-core/src/jvmTest/kotlin/com/squareup/workflow1/JvmWorkflowIdentifierTest.kt b/workflow-core/src/jvmTest/kotlin/com/squareup/workflow1/JvmWorkflowIdentifierTest.kt index 272d3eb703..922e7911d7 100644 --- a/workflow-core/src/jvmTest/kotlin/com/squareup/workflow1/JvmWorkflowIdentifierTest.kt +++ b/workflow-core/src/jvmTest/kotlin/com/squareup/workflow1/JvmWorkflowIdentifierTest.kt @@ -24,6 +24,7 @@ class JvmWorkflowIdentifierTest { fun `impostor identifier toString uses full chain when describeRealIdentifier returns null`() { class TestImpostor : Workflow, ImpostorWorkflow { override val realIdentifier: WorkflowIdentifier = TestWorkflow1.identifier + override val identifier: WorkflowIdentifier = computeIdentifier() override fun describeRealIdentifier(): String? = null override fun asStatefulWorkflow(): StatefulWorkflow = diff --git a/workflow-runtime/src/commonMain/kotlin/com/squareup/workflow1/internal/SubtreeManager.kt b/workflow-runtime/src/commonMain/kotlin/com/squareup/workflow1/internal/SubtreeManager.kt index 38504d33fd..284cff9c02 100644 --- a/workflow-runtime/src/commonMain/kotlin/com/squareup/workflow1/internal/SubtreeManager.kt +++ b/workflow-runtime/src/commonMain/kotlin/com/squareup/workflow1/internal/SubtreeManager.kt @@ -7,7 +7,6 @@ import com.squareup.workflow1.Workflow import com.squareup.workflow1.WorkflowAction import com.squareup.workflow1.WorkflowInterceptor import com.squareup.workflow1.WorkflowInterceptor.WorkflowSession -import com.squareup.workflow1.identifier import kotlinx.coroutines.selects.SelectBuilder import kotlin.coroutines.CoroutineContext diff --git a/workflow-runtime/src/commonMain/kotlin/com/squareup/workflow1/internal/WorkflowNodeId.kt b/workflow-runtime/src/commonMain/kotlin/com/squareup/workflow1/internal/WorkflowNodeId.kt index e8b765c2df..b6dd91e824 100644 --- a/workflow-runtime/src/commonMain/kotlin/com/squareup/workflow1/internal/WorkflowNodeId.kt +++ b/workflow-runtime/src/commonMain/kotlin/com/squareup/workflow1/internal/WorkflowNodeId.kt @@ -2,7 +2,6 @@ package com.squareup.workflow1.internal import com.squareup.workflow1.Workflow import com.squareup.workflow1.WorkflowIdentifier -import com.squareup.workflow1.identifier import com.squareup.workflow1.readByteStringWithLength import com.squareup.workflow1.readUtf8WithLength import com.squareup.workflow1.writeByteStringWithLength diff --git a/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/TreeSnapshotTest.kt b/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/TreeSnapshotTest.kt index f52d94da3f..350ca103c0 100644 --- a/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/TreeSnapshotTest.kt +++ b/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/TreeSnapshotTest.kt @@ -115,19 +115,23 @@ internal class TreeSnapshotTest { private object Workflow1 : Workflow { override fun asStatefulWorkflow(): StatefulWorkflow = fail() + override val identifier: WorkflowIdentifier = computeIdentifier() } private object Workflow2 : Workflow { override fun asStatefulWorkflow(): StatefulWorkflow = fail() + override val identifier: WorkflowIdentifier = computeIdentifier() } private object UnsnapshottableWorkflow1 : Workflow, ImpostorWorkflow { override val realIdentifier = unsnapshottableIdentifier(typeOf()) override fun asStatefulWorkflow(): StatefulWorkflow = fail() + override val identifier: WorkflowIdentifier = computeIdentifier() } private object UnsnapshottableWorkflow2 : Workflow, ImpostorWorkflow { override val realIdentifier = unsnapshottableIdentifier(typeOf()) override fun asStatefulWorkflow(): StatefulWorkflow = fail() + override val identifier: WorkflowIdentifier = computeIdentifier() } } diff --git a/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/internal/ChainedWorkflowInterceptorTest.kt b/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/internal/ChainedWorkflowInterceptorTest.kt index 441687de13..57d7f7e944 100644 --- a/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/internal/ChainedWorkflowInterceptorTest.kt +++ b/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/internal/ChainedWorkflowInterceptorTest.kt @@ -12,7 +12,6 @@ import com.squareup.workflow1.WorkflowIdentifier import com.squareup.workflow1.WorkflowInterceptor import com.squareup.workflow1.WorkflowInterceptor.RenderContextInterceptor import com.squareup.workflow1.WorkflowInterceptor.WorkflowSession -import com.squareup.workflow1.identifier import com.squareup.workflow1.parse import com.squareup.workflow1.rendering import kotlinx.coroutines.CoroutineScope diff --git a/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/internal/SubtreeManagerTest.kt b/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/internal/SubtreeManagerTest.kt index 387aa9145f..4915128f81 100644 --- a/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/internal/SubtreeManagerTest.kt +++ b/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/internal/SubtreeManagerTest.kt @@ -10,7 +10,6 @@ import com.squareup.workflow1.WorkflowAction import com.squareup.workflow1.WorkflowOutput import com.squareup.workflow1.action import com.squareup.workflow1.applyTo -import com.squareup.workflow1.identifier import com.squareup.workflow1.internal.SubtreeManagerTest.TestWorkflow.Rendering import kotlinx.coroutines.Dispatchers.Unconfined import kotlinx.coroutines.ExperimentalCoroutinesApi diff --git a/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/internal/WorkflowNodeTest.kt b/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/internal/WorkflowNodeTest.kt index ca889abfc8..1c5997db15 100644 --- a/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/internal/WorkflowNodeTest.kt +++ b/workflow-runtime/src/commonTest/kotlin/com/squareup/workflow1/internal/WorkflowNodeTest.kt @@ -18,7 +18,6 @@ import com.squareup.workflow1.WorkflowInterceptor.WorkflowSession import com.squareup.workflow1.WorkflowOutput import com.squareup.workflow1.action import com.squareup.workflow1.contraMap -import com.squareup.workflow1.identifier import com.squareup.workflow1.parse import com.squareup.workflow1.readUtf8WithLength import com.squareup.workflow1.renderChild diff --git a/workflow-testing/src/main/java/com/squareup/workflow1/testing/RealRenderTester.kt b/workflow-testing/src/main/java/com/squareup/workflow1/testing/RealRenderTester.kt index 6603330d43..cafb8f2cae 100644 --- a/workflow-testing/src/main/java/com/squareup/workflow1/testing/RealRenderTester.kt +++ b/workflow-testing/src/main/java/com/squareup/workflow1/testing/RealRenderTester.kt @@ -14,7 +14,6 @@ import com.squareup.workflow1.WorkflowIdentifierType.Snapshottable import com.squareup.workflow1.WorkflowIdentifierType.Unsnapshottable import com.squareup.workflow1.WorkflowOutput import com.squareup.workflow1.applyTo -import com.squareup.workflow1.identifier import com.squareup.workflow1.testing.RealRenderTester.Expectation import com.squareup.workflow1.testing.RealRenderTester.Expectation.ExpectedSideEffect import com.squareup.workflow1.testing.RealRenderTester.Expectation.ExpectedWorker diff --git a/workflow-testing/src/main/java/com/squareup/workflow1/testing/RenderTester.kt b/workflow-testing/src/main/java/com/squareup/workflow1/testing/RenderTester.kt index ce3c310c33..fe471234a4 100644 --- a/workflow-testing/src/main/java/com/squareup/workflow1/testing/RenderTester.kt +++ b/workflow-testing/src/main/java/com/squareup/workflow1/testing/RenderTester.kt @@ -5,7 +5,6 @@ import com.squareup.workflow1.Workflow import com.squareup.workflow1.WorkflowAction import com.squareup.workflow1.WorkflowIdentifier import com.squareup.workflow1.WorkflowOutput -import com.squareup.workflow1.identifier import com.squareup.workflow1.testing.RenderTester.ChildWorkflowMatch import com.squareup.workflow1.workflowIdentifier import kotlin.reflect.KClass diff --git a/workflow-testing/src/test/java/com/squareup/workflow1/testing/RealRenderTesterTest.kt b/workflow-testing/src/test/java/com/squareup/workflow1/testing/RealRenderTesterTest.kt index 43798bfb65..2184685723 100644 --- a/workflow-testing/src/test/java/com/squareup/workflow1/testing/RealRenderTesterTest.kt +++ b/workflow-testing/src/test/java/com/squareup/workflow1/testing/RealRenderTesterTest.kt @@ -14,8 +14,8 @@ import com.squareup.workflow1.WorkflowIdentifier import com.squareup.workflow1.WorkflowOutput import com.squareup.workflow1.action import com.squareup.workflow1.asWorker +import com.squareup.workflow1.computeIdentifier import com.squareup.workflow1.contraMap -import com.squareup.workflow1.identifier import com.squareup.workflow1.renderChild import com.squareup.workflow1.rendering import com.squareup.workflow1.runningWorker @@ -827,12 +827,15 @@ internal class RealRenderTesterTest { class TestWorkflow : Workflow { override fun asStatefulWorkflow(): StatefulWorkflow = throw NotImplementedError() + + override val identifier: WorkflowIdentifier = computeIdentifier() } class TestImpostor(val proxy: Workflow<*, *, *>) : Workflow, ImpostorWorkflow { override val realIdentifier: WorkflowIdentifier get() = proxy.identifier + override val identifier: WorkflowIdentifier = computeIdentifier() override fun asStatefulWorkflow(): StatefulWorkflow = throw NotImplementedError() } @@ -853,17 +856,22 @@ internal class RealRenderTesterTest { class TestWorkflowActual : Workflow { override fun asStatefulWorkflow(): StatefulWorkflow = throw NotImplementedError() + + override val identifier: WorkflowIdentifier = computeIdentifier() } class TestWorkflowExpected : Workflow { override fun asStatefulWorkflow(): StatefulWorkflow = throw NotImplementedError() + + override val identifier: WorkflowIdentifier = computeIdentifier() } class TestImpostor(val proxy: Workflow<*, *, *>) : Workflow, ImpostorWorkflow { override val realIdentifier: WorkflowIdentifier get() = proxy.identifier + override val identifier: WorkflowIdentifier = computeIdentifier() override fun asStatefulWorkflow(): StatefulWorkflow = throw NotImplementedError() } @@ -891,12 +899,14 @@ internal class RealRenderTesterTest { class TestWorkflow : Workflow { override fun asStatefulWorkflow(): StatefulWorkflow = throw NotImplementedError() + override val identifier: WorkflowIdentifier = computeIdentifier() } class TestImpostorActual(val proxy: Workflow<*, *, *>) : Workflow, ImpostorWorkflow { override val realIdentifier: WorkflowIdentifier get() = proxy.identifier + override val identifier: WorkflowIdentifier = computeIdentifier() override fun asStatefulWorkflow(): StatefulWorkflow = throw NotImplementedError() } @@ -905,6 +915,7 @@ internal class RealRenderTesterTest { Workflow, ImpostorWorkflow { override val realIdentifier: WorkflowIdentifier get() = proxy.identifier + override val identifier: WorkflowIdentifier = computeIdentifier() override fun asStatefulWorkflow(): StatefulWorkflow = throw NotImplementedError() } @@ -1253,6 +1264,8 @@ internal class RealRenderTesterTest { val workflow = object : Workflow { override fun asStatefulWorkflow(): StatefulWorkflow = throw NotImplementedError() + + override val identifier: WorkflowIdentifier = computeIdentifier() } val invocation = createRenderChildInvocation(workflow, "props", "key") @@ -1473,38 +1486,40 @@ internal class RealRenderTesterTest { @Test fun `realTypeMatchesExpectation() matches mockito mock of expected interface`() { val expected = TestWorkflowInterface::class.workflowIdentifier - val actual = mock().identifier + val actual = mock().computeIdentifier() assertTrue(actual.realTypeMatchesExpectation(expected)) } @Test fun `realTypeMatchesExpectation() matches mockito mock of expected abstract class`() { val expected = ExpectedWorkflowClass::class.workflowIdentifier - val actual = mock().identifier + val actual = mock().computeIdentifier() assertTrue(actual.realTypeMatchesExpectation(expected)) } @Test fun `realTypeMatchesExpectation() doesn't match mockito mock of unexpected interface`() { val expected = TestWorkflowInterface::class.workflowIdentifier - val actual = mock>().identifier + val actual = mock>().computeIdentifier() assertFalse(actual.realTypeMatchesExpectation(expected)) } @Test fun `realTypeMatchesExpectation() doesn't match mockito mock of unexpected abstract class`() { val expected = ExpectedWorkflowClass::class.workflowIdentifier - val actual = mock().identifier + val actual = mock().computeIdentifier() assertFalse(actual.realTypeMatchesExpectation(expected)) } @Test fun `realTypeMatchesExpectation() handles mockk mocks`() { val expected = TestWorkflowInterface::class.workflowIdentifier - val actual = mockk().identifier + val actual = mockk().computeIdentifier() assertTrue(actual.realTypeMatchesExpectation(expected)) } private object TestWorkflow : Workflow { override fun asStatefulWorkflow(): StatefulWorkflow = throw NotImplementedError() + + override val identifier: WorkflowIdentifier = computeIdentifier() } @Suppress("unused")