Skip to content

Commit 35d2beb

Browse files
Merge pull request #127 from square/zachklipp/extract-default-methods
Extract public interface methods with default implementations into extension methods.
2 parents 9f38c52 + 0ee43a4 commit 35d2beb

File tree

6 files changed

+229
-174
lines changed

6 files changed

+229
-174
lines changed

workflow-core/api/workflow-core.api

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
public abstract interface class com/squareup/workflow1/BaseRenderContext {
22
public abstract fun getActionSink ()Lcom/squareup/workflow1/Sink;
3-
public abstract fun makeActionSink ()Lcom/squareup/workflow1/Sink;
4-
public abstract fun onEvent (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1;
53
public abstract fun renderChild (Lcom/squareup/workflow1/Workflow;Ljava/lang/Object;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
64
public abstract fun runningSideEffect (Ljava/lang/String;Lkotlin/jvm/functions/Function1;)V
75
}
86

97
public final class com/squareup/workflow1/BaseRenderContext$DefaultImpls {
10-
public static fun makeActionSink (Lcom/squareup/workflow1/BaseRenderContext;)Lcom/squareup/workflow1/Sink;
11-
public static fun onEvent (Lcom/squareup/workflow1/BaseRenderContext;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1;
128
public static synthetic fun renderChild$default (Lcom/squareup/workflow1/BaseRenderContext;Lcom/squareup/workflow1/Workflow;Ljava/lang/Object;Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/Object;
139
}
1410

@@ -114,8 +110,6 @@ public abstract class com/squareup/workflow1/StatefulWorkflow : com/squareup/wor
114110

115111
public final class com/squareup/workflow1/StatefulWorkflow$RenderContext : com/squareup/workflow1/BaseRenderContext {
116112
public fun getActionSink ()Lcom/squareup/workflow1/Sink;
117-
public fun makeActionSink ()Lcom/squareup/workflow1/Sink;
118-
public fun onEvent (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1;
119113
public fun renderChild (Lcom/squareup/workflow1/Workflow;Ljava/lang/Object;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
120114
public fun runningSideEffect (Ljava/lang/String;Lkotlin/jvm/functions/Function1;)V
121115
}
@@ -128,8 +122,6 @@ public abstract class com/squareup/workflow1/StatelessWorkflow : com/squareup/wo
128122

129123
public final class com/squareup/workflow1/StatelessWorkflow$RenderContext : com/squareup/workflow1/BaseRenderContext {
130124
public fun getActionSink ()Lcom/squareup/workflow1/Sink;
131-
public fun makeActionSink ()Lcom/squareup/workflow1/Sink;
132-
public fun onEvent (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1;
133125
public fun renderChild (Lcom/squareup/workflow1/Workflow;Ljava/lang/Object;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
134126
public fun runningSideEffect (Ljava/lang/String;Lkotlin/jvm/functions/Function1;)V
135127
}
@@ -234,6 +226,7 @@ public final class com/squareup/workflow1/Workflows {
234226
public static final fun invoke (Lcom/squareup/workflow1/EventHandler;)V
235227
public static final fun makeEventSink (Lcom/squareup/workflow1/BaseRenderContext;Lkotlin/jvm/functions/Function2;)Lcom/squareup/workflow1/Sink;
236228
public static final fun mapRendering (Lcom/squareup/workflow1/Workflow;Lkotlin/jvm/functions/Function1;)Lcom/squareup/workflow1/Workflow;
229+
public static final fun onEvent (Lcom/squareup/workflow1/BaseRenderContext;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1;
237230
public static final fun renderChild (Lcom/squareup/workflow1/BaseRenderContext;Lcom/squareup/workflow1/Workflow;Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;
238231
public static final fun renderChild (Lcom/squareup/workflow1/BaseRenderContext;Lcom/squareup/workflow1/Workflow;Ljava/lang/String;)Ljava/lang/Object;
239232
public static final fun renderChild (Lcom/squareup/workflow1/BaseRenderContext;Lcom/squareup/workflow1/Workflow;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;

workflow-core/src/main/java/com/squareup/workflow1/RenderContext.kt

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package com.squareup.workflow1
2121

22+
import com.squareup.workflow1.StatefulWorkflow.RenderContext
2223
import com.squareup.workflow1.WorkflowAction.Companion.noAction
2324
import com.squareup.workflow1.WorkflowAction.Updater
2425
import kotlin.reflect.KType
@@ -63,26 +64,6 @@ interface BaseRenderContext<out PropsT, StateT, in OutputT> {
6364
*/
6465
val actionSink: Sink<WorkflowAction<PropsT, StateT, OutputT>>
6566

66-
@Deprecated("Use RenderContext.actionSink.")
67-
@Suppress("DEPRECATION")
68-
fun <EventT : Any> onEvent(
69-
handler: (EventT) -> WorkflowAction<PropsT, StateT, OutputT>
70-
): (EventT) -> Unit = EventHandler { event ->
71-
// Run the handler synchronously, so we only have to emit the resulting action and don't
72-
// need the update channel to be generic on each event type.
73-
val action = handler(event)
74-
actionSink.send(action)
75-
}
76-
77-
/**
78-
* Creates a sink that will accept a single [WorkflowAction] of the given type.
79-
* Invokes that action by calling [WorkflowAction.apply] to update the current
80-
* state, and optionally emits the returned output value if it is non-null.
81-
*/
82-
@Suppress("UNCHECKED_CAST", "DeprecatedCallableAddReplaceWith")
83-
@Deprecated("Use RenderContext.actionSink.")
84-
fun <A : WorkflowAction<PropsT, StateT, OutputT>> makeActionSink(): Sink<A> = actionSink
85-
8667
/**
8768
* Ensures [child] is running as a child of this workflow, and returns the result of its
8869
* `render` method.
@@ -137,6 +118,17 @@ interface BaseRenderContext<out PropsT, StateT, in OutputT> {
137118
)
138119
}
139120

121+
@Deprecated("Use RenderContext.actionSink.")
122+
@Suppress("DEPRECATION")
123+
fun <EventT : Any, PropsT, StateT, OutputT> BaseRenderContext<PropsT, StateT, OutputT>.onEvent(
124+
handler: (EventT) -> WorkflowAction<PropsT, StateT, OutputT>
125+
): (EventT) -> Unit = EventHandler { event ->
126+
// Run the handler synchronously, so we only have to emit the resulting action and don't
127+
// need the update channel to be generic on each event type.
128+
val action = handler(event)
129+
actionSink.send(action)
130+
}
131+
140132
/**
141133
* Convenience alias of [RenderContext.renderChild] for workflows that don't take props.
142134
*/

workflow-runtime/src/test/java/com/squareup/workflow1/internal/RealRenderContextTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import com.squareup.workflow1.internal.RealRenderContext.Renderer
3232
import com.squareup.workflow1.internal.RealRenderContext.SideEffectRunner
3333
import com.squareup.workflow1.internal.RealRenderContextTest.TestRenderer.Rendering
3434
import com.squareup.workflow1.makeEventSink
35+
import com.squareup.workflow1.onEvent
3536
import com.squareup.workflow1.renderChild
3637
import com.squareup.workflow1.stateless
3738
import kotlinx.coroutines.channels.Channel

workflow-testing/api/workflow-testing.api

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ public abstract interface class com/squareup/workflow1/testing/RenderTestResult
1414

1515
public abstract interface class com/squareup/workflow1/testing/RenderTester {
1616
public abstract fun expectSideEffect (Ljava/lang/String;ZLkotlin/jvm/functions/Function1;)Lcom/squareup/workflow1/testing/RenderTester;
17-
public abstract fun expectWorkflow (Lcom/squareup/workflow1/WorkflowIdentifier;Ljava/lang/Object;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lcom/squareup/workflow1/WorkflowOutput;Ljava/lang/String;)Lcom/squareup/workflow1/testing/RenderTester;
1817
public abstract fun expectWorkflow (Ljava/lang/String;ZLkotlin/jvm/functions/Function1;)Lcom/squareup/workflow1/testing/RenderTester;
19-
public abstract fun expectWorkflow (Lkotlin/reflect/KClass;Ljava/lang/Object;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lcom/squareup/workflow1/WorkflowOutput;Ljava/lang/String;)Lcom/squareup/workflow1/testing/RenderTester;
2018
public abstract fun render (Lkotlin/jvm/functions/Function1;)Lcom/squareup/workflow1/testing/RenderTestResult;
2119
}
2220

@@ -36,11 +34,7 @@ public final class com/squareup/workflow1/testing/RenderTester$ChildWorkflowMatc
3634

3735
public final class com/squareup/workflow1/testing/RenderTester$DefaultImpls {
3836
public static synthetic fun expectSideEffect$default (Lcom/squareup/workflow1/testing/RenderTester;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lcom/squareup/workflow1/testing/RenderTester;
39-
public static fun expectWorkflow (Lcom/squareup/workflow1/testing/RenderTester;Lcom/squareup/workflow1/WorkflowIdentifier;Ljava/lang/Object;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lcom/squareup/workflow1/WorkflowOutput;Ljava/lang/String;)Lcom/squareup/workflow1/testing/RenderTester;
40-
public static fun expectWorkflow (Lcom/squareup/workflow1/testing/RenderTester;Lkotlin/reflect/KClass;Ljava/lang/Object;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lcom/squareup/workflow1/WorkflowOutput;Ljava/lang/String;)Lcom/squareup/workflow1/testing/RenderTester;
41-
public static synthetic fun expectWorkflow$default (Lcom/squareup/workflow1/testing/RenderTester;Lcom/squareup/workflow1/WorkflowIdentifier;Ljava/lang/Object;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lcom/squareup/workflow1/WorkflowOutput;Ljava/lang/String;ILjava/lang/Object;)Lcom/squareup/workflow1/testing/RenderTester;
4237
public static synthetic fun expectWorkflow$default (Lcom/squareup/workflow1/testing/RenderTester;Ljava/lang/String;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lcom/squareup/workflow1/testing/RenderTester;
43-
public static synthetic fun expectWorkflow$default (Lcom/squareup/workflow1/testing/RenderTester;Lkotlin/reflect/KClass;Ljava/lang/Object;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lcom/squareup/workflow1/WorkflowOutput;Ljava/lang/String;ILjava/lang/Object;)Lcom/squareup/workflow1/testing/RenderTester;
4438
public static synthetic fun render$default (Lcom/squareup/workflow1/testing/RenderTester;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lcom/squareup/workflow1/testing/RenderTestResult;
4539
}
4640

@@ -55,6 +49,12 @@ public final class com/squareup/workflow1/testing/RenderTester$RenderChildInvoca
5549

5650
public final class com/squareup/workflow1/testing/RenderTesterKt {
5751
public static final fun expectSideEffect (Lcom/squareup/workflow1/testing/RenderTester;Ljava/lang/String;)Lcom/squareup/workflow1/testing/RenderTester;
52+
public static final fun expectWorkflow (Lcom/squareup/workflow1/testing/RenderTester;Lcom/squareup/workflow1/WorkflowIdentifier;Ljava/lang/Object;Lcom/squareup/workflow1/WorkflowOutput;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Lcom/squareup/workflow1/testing/RenderTester;
53+
public static final fun expectWorkflow (Lcom/squareup/workflow1/testing/RenderTester;Lcom/squareup/workflow1/WorkflowIdentifier;Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Lcom/squareup/workflow1/testing/RenderTester;
54+
public static final fun expectWorkflow (Lcom/squareup/workflow1/testing/RenderTester;Lkotlin/reflect/KClass;Ljava/lang/Object;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lcom/squareup/workflow1/WorkflowOutput;Ljava/lang/String;)Lcom/squareup/workflow1/testing/RenderTester;
55+
public static synthetic fun expectWorkflow$default (Lcom/squareup/workflow1/testing/RenderTester;Lcom/squareup/workflow1/WorkflowIdentifier;Ljava/lang/Object;Lcom/squareup/workflow1/WorkflowOutput;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lcom/squareup/workflow1/testing/RenderTester;
56+
public static synthetic fun expectWorkflow$default (Lcom/squareup/workflow1/testing/RenderTester;Lcom/squareup/workflow1/WorkflowIdentifier;Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lcom/squareup/workflow1/testing/RenderTester;
57+
public static synthetic fun expectWorkflow$default (Lcom/squareup/workflow1/testing/RenderTester;Lkotlin/reflect/KClass;Ljava/lang/Object;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lcom/squareup/workflow1/WorkflowOutput;Ljava/lang/String;ILjava/lang/Object;)Lcom/squareup/workflow1/testing/RenderTester;
5858
public static final fun renderTester (Lcom/squareup/workflow1/StatefulWorkflow;Ljava/lang/Object;Ljava/lang/Object;)Lcom/squareup/workflow1/testing/RenderTester;
5959
public static final fun renderTester (Lcom/squareup/workflow1/Workflow;Ljava/lang/Object;)Lcom/squareup/workflow1/testing/RenderTester;
6060
public static final fun testRender (Lcom/squareup/workflow1/StatefulWorkflow;Ljava/lang/Object;Ljava/lang/Object;)Lcom/squareup/workflow1/testing/RenderTester;

0 commit comments

Comments
 (0)