diff --git a/kotlin/samples/tictactoe/common/src/main/java/com/squareup/sample/gameworkflow/RunGameWorkflow.kt b/kotlin/samples/tictactoe/common/src/main/java/com/squareup/sample/gameworkflow/RunGameWorkflow.kt index e20746f78..65e36b05b 100644 --- a/kotlin/samples/tictactoe/common/src/main/java/com/squareup/sample/gameworkflow/RunGameWorkflow.kt +++ b/kotlin/samples/tictactoe/common/src/main/java/com/squareup/sample/gameworkflow/RunGameWorkflow.kt @@ -106,10 +106,10 @@ class RealRunGameWorkflow( } is Playing -> { - // context.compose starts takeTurnsWorkflow, or keeps it running if it was + // context.composeChild starts takeTurnsWorkflow, or keeps it running if it was // already going. TakeTurnsWorkflow.compose is immediately called, // and the GamePlayScreen it renders is immediately returned. - val takeTurnsScreen = context.compose(takeTurnsWorkflow, state.playerInfo) { output -> + val takeTurnsScreen = context.composeChild(takeTurnsWorkflow, state.playerInfo) { output -> when (output.ending) { Quitted -> enterState(MaybeQuitting(output, state.playerInfo)) else -> enterState(GameOver(state.playerInfo, output)) diff --git a/kotlin/samples/tictactoe/common/src/main/java/com/squareup/sample/mainworkflow/MainWorkflow.kt b/kotlin/samples/tictactoe/common/src/main/java/com/squareup/sample/mainworkflow/MainWorkflow.kt index 2d60be3f1..ca4967ec5 100644 --- a/kotlin/samples/tictactoe/common/src/main/java/com/squareup/sample/mainworkflow/MainWorkflow.kt +++ b/kotlin/samples/tictactoe/common/src/main/java/com/squareup/sample/mainworkflow/MainWorkflow.kt @@ -29,7 +29,7 @@ import com.squareup.workflow.StatefulWorkflow import com.squareup.workflow.Workflow import com.squareup.workflow.WorkflowAction.Companion.enterState import com.squareup.workflow.WorkflowContext -import com.squareup.workflow.compose +import com.squareup.workflow.composeChild /** * Application specific root [Workflow], and demonstration of workflow composition. @@ -59,13 +59,13 @@ class MainWorkflow( context: WorkflowContext ): RunGameScreen = when (state) { is Authenticating -> { - val authScreen = context.compose(authWorkflow) { enterState(RunningGame) } + val authScreen = context.composeChild(authWorkflow) { enterState(RunningGame) } val emptyGameScreen = GamePlayScreen() AlertContainerScreen(authScreen.asPanelOver(emptyGameScreen)) } - is RunningGame -> context.compose(runGameWorkflow) { enterState(Authenticating) } + is RunningGame -> context.composeChild(runGameWorkflow) { enterState(Authenticating) } } override fun snapshotState(state: MainState): Snapshot = state.toSnapshot() diff --git a/kotlin/workflow-core/src/main/java/com/squareup/workflow/StatefulWorkflow.kt b/kotlin/workflow-core/src/main/java/com/squareup/workflow/StatefulWorkflow.kt index 1444dd4f8..9c5a69255 100644 --- a/kotlin/workflow-core/src/main/java/com/squareup/workflow/StatefulWorkflow.kt +++ b/kotlin/workflow-core/src/main/java/com/squareup/workflow/StatefulWorkflow.kt @@ -17,7 +17,7 @@ package com.squareup.workflow /** * A composable, stateful object that can [handle events][WorkflowContext.onEvent], - * [delegate to children][WorkflowContext.compose], [subscribe][onReceive] to arbitrary streams from + * [delegate to children][WorkflowContext.composeChild], [subscribe][onReceive] to arbitrary streams from * the outside world, and be [saved][snapshotState] to a serialized form to be restored later. * * The basic purpose of a `Workflow` is to take some [input][InputT] and return a @@ -63,7 +63,7 @@ abstract class StatefulWorkflow< > : Workflow { /** - * Called from [WorkflowContext.compose] when the state machine is first started, to get the + * Called from [WorkflowContext.composeChild] when the state machine is first started, to get the * initial state. * * @param snapshot @@ -78,7 +78,7 @@ abstract class StatefulWorkflow< ): StateT /** - * Called from [WorkflowContext.compose] instead of [initialState] when the workflow is already + * Called from [WorkflowContext.composeChild] instead of [initialState] when the workflow is already * running. This allows the workflow to detect changes in input, and possibly change its state in * response. This method is called eagerly: `old` and `new` might be the same value, so it is up * to implementing code to perform any diffing if desired. @@ -100,7 +100,7 @@ abstract class StatefulWorkflow< * - Emits an output. * * **Never call this method directly.** To nest the rendering of a child workflow in your own, - * pass the child and any required input to [WorkflowContext.compose]. + * pass the child and any required input to [WorkflowContext.composeChild]. * * This method *should not* have any side effects, and in particular should not do anything that * blocks the current thread. It may be called multiple times for the same state. It must do all its diff --git a/kotlin/workflow-core/src/main/java/com/squareup/workflow/StatelessWorkflow.kt b/kotlin/workflow-core/src/main/java/com/squareup/workflow/StatelessWorkflow.kt index 42b255fe9..842aab88f 100644 --- a/kotlin/workflow-core/src/main/java/com/squareup/workflow/StatelessWorkflow.kt +++ b/kotlin/workflow-core/src/main/java/com/squareup/workflow/StatelessWorkflow.kt @@ -61,7 +61,7 @@ abstract class StatelessWorkflow * - Emits an output. * * **Never call this method directly.** To get the rendering from a child workflow, pass the child - * and any required input to [WorkflowContext.compose]. + * and any required input to [WorkflowContext.composeChild]. * * This method *should not* have any side effects, and in particular should not do anything that * blocks the current thread. It may be called multiple times for the same state. It must do all its @@ -137,6 +137,6 @@ fun transform: (FromRenderingT) -> ToRenderingT ): Workflow = Workflow.stateless { input, context -> // @formatter:on - context.compose(this@mapRendering, input) { emitOutput(it) } + context.composeChild(this@mapRendering, input) { emitOutput(it) } .let(transform) } diff --git a/kotlin/workflow-core/src/main/java/com/squareup/workflow/Workflow.kt b/kotlin/workflow-core/src/main/java/com/squareup/workflow/Workflow.kt index 780ca7f06..f7a456feb 100644 --- a/kotlin/workflow-core/src/main/java/com/squareup/workflow/Workflow.kt +++ b/kotlin/workflow-core/src/main/java/com/squareup/workflow/Workflow.kt @@ -17,7 +17,7 @@ package com.squareup.workflow /** * A composable, optionally-stateful object that can [handle events][WorkflowContext.onEvent], - * [delegate to children][WorkflowContext.compose], [subscribe][onReceive] to arbitrary streams from + * [delegate to children][WorkflowContext.composeChild], [subscribe][onReceive] to arbitrary streams from * the outside world. * * The basic purpose of a `Workflow` is to take some [input][InputT] and return a @@ -67,7 +67,7 @@ package com.squareup.workflow * to its parent. * May be [Nothing] if the workflow doesn't need to emit anything. * - * @param RenderingT The value returned to this workflow's parent during [composition][compose]. + * @param RenderingT The value returned to this workflow's parent during [composition][composeChild]. * Typically represents a "view" of this workflow's input, current state, and children's renderings. * A workflow that represents a UI component may use a view model as its rendering type. * @@ -78,7 +78,7 @@ interface Workflow { /** * Provides a [StatefulWorkflow] view of this workflow. Necessary because [StatefulWorkflow] is - * the common API required for [WorkflowContext.compose] to do its work. + * the common API required for [WorkflowContext.composeChild] to do its work. */ fun asStatefulWorkflow(): StatefulWorkflow diff --git a/kotlin/workflow-core/src/main/java/com/squareup/workflow/WorkflowContext.kt b/kotlin/workflow-core/src/main/java/com/squareup/workflow/WorkflowContext.kt index 16a503dbc..f96214ac4 100644 --- a/kotlin/workflow-core/src/main/java/com/squareup/workflow/WorkflowContext.kt +++ b/kotlin/workflow-core/src/main/java/com/squareup/workflow/WorkflowContext.kt @@ -41,7 +41,7 @@ import kotlin.reflect.KType * * ## Composing Children * - * See [compose]. + * See [composeChild]. * * ## Handling Workflow Teardown * @@ -126,7 +126,7 @@ interface WorkflowContext { * @param key An optional string key that is used to distinguish between workflows of the same * type. */ - fun compose( + fun composeChild( child: Workflow, input: ChildInputT, key: String = "", @@ -137,7 +137,7 @@ interface WorkflowContext { * Adds an action to be invoked if the workflow is discarded by its parent before the next * compose pass. Multiple hooks can be registered in the same compose pass, they will be invoked * in the same order they're set. Like any other work performed through the context (e.g. calls - * to [compose] or [onReceive]), hooks are cleared at the start of each compose pass, so you must + * to [composeChild] or [onReceive]), hooks are cleared at the start of each composeChild pass, so you must * set any hooks you need in each compose pass. * * Teardown handlers should be non-blocking and execute quickly, since they are invoked @@ -176,46 +176,46 @@ inline fun WorkflowContext - WorkflowContext.compose( + WorkflowContext.composeChild( // Intellij refuses to format this parameter list correctly because of the weird line break, // and detekt will complain about it. // @formatter:off child: Workflow, key: String = "", handler: (ChildOutputT) -> WorkflowAction - ): ChildRenderingT = compose(child, Unit, key, handler) + ): ChildRenderingT = composeChild(child, Unit, key, handler) // @formatter:on /** - * Convenience alias of [WorkflowContext.compose] for workflows that don't take input or emit + * Convenience alias of [WorkflowContext.composeChild] for workflows that don't take input or emit * output. */ fun - WorkflowContext.compose( + WorkflowContext.composeChild( // Intellij refuses to format this parameter list correctly because of the weird line break, // and detekt will complain about it. // @formatter:off child: Workflow, input: InputT, key: String = "" - ): ChildRenderingT = compose(child, input, key) { WorkflowAction.noop() } + ): ChildRenderingT = composeChild(child, input, key) { WorkflowAction.noop() } // @formatter:on /** - * Convenience alias of [WorkflowContext.compose] for workflows that don't take input or emit + * Convenience alias of [WorkflowContext.composeChild] for workflows that don't take input or emit * output. */ fun - WorkflowContext.compose( + WorkflowContext.composeChild( // Intellij refuses to format this parameter list correctly because of the weird line break, // and detekt will complain about it. // @formatter:off child: Workflow, key: String = "" - ): ChildRenderingT = compose(child, Unit, key) { WorkflowAction.noop() } + ): ChildRenderingT = composeChild(child, Unit, key) { WorkflowAction.noop() } // @formatter:on /** diff --git a/kotlin/workflow-runtime/src/main/java/com/squareup/workflow/internal/RealWorkflowContext.kt b/kotlin/workflow-runtime/src/main/java/com/squareup/workflow/internal/RealWorkflowContext.kt index 70fa31165..9da9a0017 100644 --- a/kotlin/workflow-runtime/src/main/java/com/squareup/workflow/internal/RealWorkflowContext.kt +++ b/kotlin/workflow-runtime/src/main/java/com/squareup/workflow/internal/RealWorkflowContext.kt @@ -75,7 +75,7 @@ internal class RealWorkflowContext( // @formatter:off override fun - compose( + composeChild( child: Workflow, input: ChildInputT, key: String, diff --git a/kotlin/workflow-runtime/src/test/java/com/squareup/workflow/internal/RealWorkflowContextTest.kt b/kotlin/workflow-runtime/src/test/java/com/squareup/workflow/internal/RealWorkflowContextTest.kt index 2709b7dae..0134d8ad5 100644 --- a/kotlin/workflow-runtime/src/test/java/com/squareup/workflow/internal/RealWorkflowContextTest.kt +++ b/kotlin/workflow-runtime/src/test/java/com/squareup/workflow/internal/RealWorkflowContextTest.kt @@ -108,11 +108,11 @@ class RealWorkflowContextTest { assertEquals("foo", output) } - @Test fun `compose works`() { + @Test fun `composeChild works`() { val context = RealWorkflowContext(TestComposer()) val workflow = TestWorkflow() - val (case, child, id, input) = context.compose(workflow, "input", "key") { output -> + val (case, child, id, input) = context.composeChild(workflow, "input", "key") { output -> emitOutput("output:$output") } diff --git a/kotlin/workflow-runtime/src/test/java/com/squareup/workflow/internal/WorkflowNodeTest.kt b/kotlin/workflow-runtime/src/test/java/com/squareup/workflow/internal/WorkflowNodeTest.kt index cfc641036..168931b29 100644 --- a/kotlin/workflow-runtime/src/test/java/com/squareup/workflow/internal/WorkflowNodeTest.kt +++ b/kotlin/workflow-runtime/src/test/java/com/squareup/workflow/internal/WorkflowNodeTest.kt @@ -24,7 +24,7 @@ import com.squareup.workflow.Workflow import com.squareup.workflow.WorkflowAction.Companion.emitOutput import com.squareup.workflow.WorkflowAction.Companion.enterState import com.squareup.workflow.WorkflowContext -import com.squareup.workflow.compose +import com.squareup.workflow.composeChild import com.squareup.workflow.invoke import com.squareup.workflow.onReceive import com.squareup.workflow.parse @@ -477,7 +477,7 @@ class WorkflowNodeTest { state: String, context: WorkflowContext ): String { - val childRendering = context.compose(childWorkflow, "child input") + val childRendering = context.composeChild(childWorkflow, "child input") return "$state|$childRendering" } diff --git a/kotlin/workflow-testing/src/test/java/com/squareup/workflow/CompositionIntegrationTest.kt b/kotlin/workflow-testing/src/test/java/com/squareup/workflow/CompositionIntegrationTest.kt index ac6cd088c..923ed7bb0 100644 --- a/kotlin/workflow-testing/src/test/java/com/squareup/workflow/CompositionIntegrationTest.kt +++ b/kotlin/workflow-testing/src/test/java/com/squareup/workflow/CompositionIntegrationTest.kt @@ -116,8 +116,8 @@ class CompositionIntegrationTest { context: WorkflowContext ): () -> Unit { if (state) { - context.compose(child1, key = "child1") - context.compose(child2, key = "child2") + context.composeChild(child1, key = "child1") + context.composeChild(child2, key = "child2") } return context.onEvent { enterState(false) }::invoke } @@ -142,7 +142,7 @@ class CompositionIntegrationTest { context.onTeardown { teardowns += "grandchild" } } val child = Workflow.stateless { context -> - context.compose(grandchild) + context.composeChild(grandchild) context.onTeardown { teardowns += "child" } } // A workflow that will render child1 and child2 until its rendering is invoked, at which point @@ -159,7 +159,7 @@ class CompositionIntegrationTest { context: WorkflowContext ): () -> Unit { if (state) { - context.compose(child) + context.composeChild(child) } return context.onEvent { enterState(false) }::invoke } diff --git a/kotlin/workflow-testing/src/test/java/com/squareup/workflow/TreeWorkflow.kt b/kotlin/workflow-testing/src/test/java/com/squareup/workflow/TreeWorkflow.kt index 6274be247..0d891506f 100644 --- a/kotlin/workflow-testing/src/test/java/com/squareup/workflow/TreeWorkflow.kt +++ b/kotlin/workflow-testing/src/test/java/com/squareup/workflow/TreeWorkflow.kt @@ -57,7 +57,7 @@ internal class TreeWorkflow( ): Rendering { val childRenderings = children .mapIndexed { index, child -> - val childRendering = context.compose(child, "$input[$index]", child.name) + val childRendering = context.composeChild(child, "$input[$index]", child.name) Pair(child.name, childRendering) } .toMap()