From 4a27e7675556aaaf521c5e65f92b81f21c82cca6 Mon Sep 17 00:00:00 2001 From: Ray Ryan Date: Mon, 29 Jun 2020 16:24:40 -0700 Subject: [PATCH] Deletes deprecated enterState and modifyState A tiny bit of convenience, a lot of landmines. --- workflow-core/api/workflow-core.api | 8 -- .../main/java/com/squareup/workflow/Worker.kt | 2 +- .../com/squareup/workflow/WorkflowAction.kt | 90 ------------------- .../workflow/internal/WorkflowNodeTest.kt | 5 +- 4 files changed, 3 insertions(+), 102 deletions(-) diff --git a/workflow-core/api/workflow-core.api b/workflow-core/api/workflow-core.api index a8e11c39a5..26865faec5 100644 --- a/workflow-core/api/workflow-core.api +++ b/workflow-core/api/workflow-core.api @@ -139,14 +139,6 @@ public abstract interface class com/squareup/workflow/WorkflowAction { } public final class com/squareup/workflow/WorkflowAction$Companion { - public final fun emitOutput (Ljava/lang/Object;)Lcom/squareup/workflow/WorkflowAction; - public final fun emitOutput (Ljava/lang/String;Ljava/lang/Object;)Lcom/squareup/workflow/WorkflowAction; - public final fun enterState (Ljava/lang/Object;Ljava/lang/Object;)Lcom/squareup/workflow/WorkflowAction; - public final fun enterState (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Lcom/squareup/workflow/WorkflowAction; - public static synthetic fun enterState$default (Lcom/squareup/workflow/WorkflowAction$Companion;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Lcom/squareup/workflow/WorkflowAction; - public static synthetic fun enterState$default (Lcom/squareup/workflow/WorkflowAction$Companion;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Lcom/squareup/workflow/WorkflowAction; - public final fun modifyState (Lkotlin/jvm/functions/Function0;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Lcom/squareup/workflow/WorkflowAction; - public static synthetic fun modifyState$default (Lcom/squareup/workflow/WorkflowAction$Companion;Lkotlin/jvm/functions/Function0;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lcom/squareup/workflow/WorkflowAction; public final fun noAction ()Lcom/squareup/workflow/WorkflowAction; } diff --git a/workflow-core/src/main/java/com/squareup/workflow/Worker.kt b/workflow-core/src/main/java/com/squareup/workflow/Worker.kt index 67c26adebd..cd54332b46 100644 --- a/workflow-core/src/main/java/com/squareup/workflow/Worker.kt +++ b/workflow-core/src/main/java/com/squareup/workflow/Worker.kt @@ -93,7 +93,7 @@ import kotlin.reflect.typeOf * ``` * class MyWorkflow(private val timeWorker: TimeWorker) { * override fun render(…): Foo { - * context.onWorkerOutput(timeWorker) { time -> emitOutput("The time is $time") } + * context.onWorkerOutput(timeWorker) { time -> action { setOutput("The time is $time") } } * } * ``` * diff --git a/workflow-core/src/main/java/com/squareup/workflow/WorkflowAction.kt b/workflow-core/src/main/java/com/squareup/workflow/WorkflowAction.kt index a4c35e9474..094d99b40d 100644 --- a/workflow-core/src/main/java/com/squareup/workflow/WorkflowAction.kt +++ b/workflow-core/src/main/java/com/squareup/workflow/WorkflowAction.kt @@ -79,96 +79,6 @@ interface WorkflowAction { fun noAction(): WorkflowAction = NO_ACTION as WorkflowAction - /** - * Convenience function that returns a [WorkflowAction] that will just set the state to - * [newState] (without considering the current state) and optionally emit an output. - */ - @Deprecated( - message = "Use action", - replaceWith = ReplaceWith( - expression = "action { state = newState }", - imports = arrayOf("com.squareup.workflow.action") - ) - ) - fun enterState( - newState: StateT, - emittingOutput: OutputT? = null - ): WorkflowAction = - action({ "enterState($newState, $emittingOutput)" }) { - state = newState - emittingOutput?.let { setOutput(it) } - } - - /** - * Convenience function that returns a [WorkflowAction] that will just set the state to - * [newState] (without considering the current state) and optionally emit an output. - */ - @Deprecated( - message = "Use action", - replaceWith = ReplaceWith( - expression = "action { state = newState }", - imports = arrayOf("com.squareup.workflow.action") - ) - ) - fun enterState( - name: String, - newState: StateT, - emittingOutput: OutputT? = null - ): WorkflowAction = - action({ "enterState($name, $newState, $emittingOutput)" }) { - state = newState - emittingOutput?.let { setOutput(it) } - } - - /** - * Convenience function to implement [WorkflowAction] without returning the output. - */ - @Deprecated( - message = "Use action", - replaceWith = ReplaceWith( - expression = "action(name) { state = state }", - imports = arrayOf("com.squareup.workflow.action") - ) - ) - fun modifyState( - name: () -> String, - emittingOutput: OutputT? = null, - modify: (StateT) -> StateT - ): WorkflowAction = - action({ "modifyState(${name()}, $emittingOutput)" }) { - state = modify(state) - emittingOutput?.let { setOutput(it) } - } - - /** - * Convenience function to implement [WorkflowAction] without changing the state. - */ - @Deprecated( - message = "Use action", - replaceWith = ReplaceWith( - expression = "action { setOutput(output) }", - imports = arrayOf("com.squareup.workflow.action") - ) - ) - fun emitOutput(output: OutputT): WorkflowAction = - action({ "emitOutput($output)" }) { setOutput(output) } - - /** - * Convenience function to implement [WorkflowAction] without changing the state. - */ - @Deprecated( - message = "Use action", - replaceWith = ReplaceWith( - expression = "action { setOutput(output) }", - imports = arrayOf("com.squareup.workflow.action") - ) - ) - fun emitOutput( - name: String, - output: OutputT - ): WorkflowAction = - action({ "emitOutput($name, $output)" }) { setOutput(output) } - private val NO_ACTION = action({ "noAction" }) { } } } diff --git a/workflow-runtime/src/test/java/com/squareup/workflow/internal/WorkflowNodeTest.kt b/workflow-runtime/src/test/java/com/squareup/workflow/internal/WorkflowNodeTest.kt index be0b1efddd..583c996c48 100644 --- a/workflow-runtime/src/test/java/com/squareup/workflow/internal/WorkflowNodeTest.kt +++ b/workflow-runtime/src/test/java/com/squareup/workflow/internal/WorkflowNodeTest.kt @@ -26,7 +26,6 @@ import com.squareup.workflow.TreeSnapshot import com.squareup.workflow.Worker import com.squareup.workflow.Workflow import com.squareup.workflow.WorkflowAction -import com.squareup.workflow.WorkflowAction.Companion.emitOutput import com.squareup.workflow.WorkflowAction.Updater import com.squareup.workflow.WorkflowIdentifier import com.squareup.workflow.WorkflowInterceptor @@ -269,10 +268,10 @@ class WorkflowNodeTest { val node = WorkflowNode(workflow.id(), workflow, "", TreeSnapshot.NONE, context) node.render(workflow, "") - sink.send(emitOutput("event")) + sink.send(action { setOutput("event") }) // Should not throw. - sink.send(emitOutput("event2")) + sink.send(action { setOutput("event2") }) } @Test fun `worker gets value`() {