Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions workflow-core/api/workflow-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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") } }
* }
* ```
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,96 +79,6 @@ interface WorkflowAction<in PropsT, StateT, out OutputT> {
fun <PropsT, StateT, OutputT> noAction(): WorkflowAction<PropsT, StateT, OutputT> =
NO_ACTION as WorkflowAction<Any?, StateT, OutputT>

/**
* 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 <StateT, OutputT> enterState(
newState: StateT,
emittingOutput: OutputT? = null
): WorkflowAction<Any?, StateT, OutputT> =
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 <StateT, OutputT> enterState(
name: String,
newState: StateT,
emittingOutput: OutputT? = null
): WorkflowAction<Any?, StateT, OutputT> =
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 <StateT, OutputT> modifyState(
name: () -> String,
emittingOutput: OutputT? = null,
modify: (StateT) -> StateT
): WorkflowAction<Any?, StateT, OutputT> =
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 <StateT, OutputT> emitOutput(output: OutputT): WorkflowAction<Any?, StateT, OutputT> =
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 <PropsT, StateT, OutputT> emitOutput(
name: String,
output: OutputT
): WorkflowAction<PropsT, StateT, OutputT> =
action({ "emitOutput($name, $output)" }) { setOutput(output) }

private val NO_ACTION = action<Any, Any, Any>({ "noAction" }) { }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`() {
Expand Down