Skip to content

Commit a5c703c

Browse files
Merge pull request #420 from square/zachklipp/rename-noop-workflowaction
Rename WorkflowAction.noop() to noAction().
2 parents 47a06c0 + 49ec599 commit a5c703c

File tree

8 files changed

+26
-23
lines changed

8 files changed

+26
-23
lines changed

kotlin/samples/hello-terminal/hello-terminal-app/src/main/java/com/squareup/sample/helloterminal/HelloTerminalWorkflow.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import com.squareup.workflow.Snapshot
2727
import com.squareup.workflow.StatefulWorkflow
2828
import com.squareup.workflow.WorkflowAction.Companion.emitOutput
2929
import com.squareup.workflow.WorkflowAction.Companion.enterState
30-
import com.squareup.workflow.WorkflowAction.Companion.noop
30+
import com.squareup.workflow.WorkflowAction.Companion.noAction
3131
import com.squareup.workflow.onWorkerOutput
3232
import com.squareup.workflow.renderChild
3333

@@ -70,7 +70,7 @@ class HelloTerminalWorkflow : TerminalWorkflow,
7070
key.keyType == Backspace -> enterState(state.backspace())
7171
key.character == 'Q' -> emitOutput(0)
7272
key.character != null -> enterState(state.append(key.character!!))
73-
else -> noop()
73+
else -> noAction()
7474
}
7575
}
7676

kotlin/samples/hello-terminal/todo-terminal-app/src/main/java/com/squareup/sample/hellotodo/EditTextWorkflow.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import com.squareup.workflow.RenderContext
1111
import com.squareup.workflow.Snapshot
1212
import com.squareup.workflow.StatefulWorkflow
1313
import com.squareup.workflow.WorkflowAction.Companion.enterState
14-
import com.squareup.workflow.WorkflowAction.Companion.noop
14+
import com.squareup.workflow.WorkflowAction.Companion.noAction
1515
import com.squareup.workflow.onWorkerOutput
1616

1717
class EditTextWorkflow : StatefulWorkflow<EditTextInput, EditTextState, String, String>() {
@@ -58,7 +58,7 @@ class EditTextWorkflow : StatefulWorkflow<EditTextInput, EditTextState, String,
5858
)
5959
Backspace -> {
6060
if (input.text.isEmpty()) {
61-
noop()
61+
noAction()
6262
} else {
6363
enterState(
6464
moveCursor(input, state, -1),
@@ -70,7 +70,7 @@ class EditTextWorkflow : StatefulWorkflow<EditTextInput, EditTextState, String,
7070
}
7171
ArrowLeft -> enterState(moveCursor(input, state, -1))
7272
ArrowRight -> enterState(moveCursor(input, state, 1))
73-
else -> noop()
73+
else -> noAction()
7474
}
7575
}
7676

kotlin/samples/hello-terminal/todo-terminal-app/src/main/java/com/squareup/sample/hellotodo/TodoWorkflow.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import com.squareup.workflow.RenderContext
2929
import com.squareup.workflow.Snapshot
3030
import com.squareup.workflow.StatefulWorkflow
3131
import com.squareup.workflow.WorkflowAction.Companion.enterState
32-
import com.squareup.workflow.WorkflowAction.Companion.noop
32+
import com.squareup.workflow.WorkflowAction.Companion.noAction
3333
import com.squareup.workflow.onWorkerOutput
3434

3535
class TodoWorkflow : TerminalWorkflow,
@@ -91,10 +91,10 @@ class TodoWorkflow : TerminalWorkflow,
9191
if (state.focusedField > TITLE_FIELD_INDEX) {
9292
enterState(state.toggleChecked(state.focusedField))
9393
} else {
94-
noop()
94+
noAction()
9595
}
9696
}
97-
else -> noop()
97+
else -> noAction()
9898
}
9999
}
100100

kotlin/samples/tictactoe/common/src/main/java/com/squareup/sample/gameworkflow/TakeTurnsWorkflow.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import com.squareup.workflow.Workflow
2727
import com.squareup.workflow.WorkflowAction
2828
import com.squareup.workflow.WorkflowAction.Companion.emitOutput
2929
import com.squareup.workflow.WorkflowAction.Companion.enterState
30-
import com.squareup.workflow.WorkflowAction.Companion.noop
30+
import com.squareup.workflow.WorkflowAction.Companion.noAction
3131

3232
typealias TakeTurnsWorkflow = Workflow<TakeTurnsInput, CompletedGame, GamePlayScreen>
3333

@@ -84,7 +84,7 @@ class RealTakeTurnsWorkflow : TakeTurnsWorkflow,
8484
val newBoard = lastTurn.board.takeSquare(event.row, event.col, lastTurn.playing)
8585

8686
return when {
87-
newBoard == lastTurn.board -> noop()
87+
newBoard == lastTurn.board -> noAction()
8888
newBoard.hasVictory() -> emitOutput(CompletedGame(Victory, lastTurn.copy(board = newBoard)))
8989
newBoard.isFull() -> emitOutput(CompletedGame(Draw, lastTurn.copy(board = newBoard)))
9090
else -> enterState(Turn(playing = lastTurn.playing.other, board = newBoard))

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ package com.squareup.workflow
2020
import com.squareup.workflow.Worker.OutputOrFinished
2121
import com.squareup.workflow.Worker.OutputOrFinished.Finished
2222
import com.squareup.workflow.Worker.OutputOrFinished.Output
23-
import com.squareup.workflow.WorkflowAction.Companion.noop
23+
import com.squareup.workflow.WorkflowAction.Companion.noAction
2424

2525
/**
2626
* Facilities for a [Workflow] to interact with other [Workflow]s and the outside world from inside
@@ -152,7 +152,7 @@ fun <InputT, StateT, OutputT : Any, ChildRenderingT>
152152
child: Workflow<InputT, Nothing, ChildRenderingT>,
153153
input: InputT,
154154
key: String = ""
155-
): ChildRenderingT = renderChild(child, input, key) { noop() }
155+
): ChildRenderingT = renderChild(child, input, key) { noAction() }
156156
// @formatter:on
157157

158158
/**
@@ -166,7 +166,7 @@ fun <StateT, OutputT : Any, ChildRenderingT>
166166
// @formatter:off
167167
child: Workflow<Unit, Nothing, ChildRenderingT>,
168168
key: String = ""
169-
): ChildRenderingT = renderChild(child, Unit, key) { noop() }
169+
): ChildRenderingT = renderChild(child, Unit, key) { noAction() }
170170
// @formatter:on
171171

172172
/**
@@ -183,7 +183,7 @@ fun <StateT, OutputT : Any, T> RenderContext<StateT, OutputT>.onWorkerOutput(
183183
) = onWorkerOutputOrFinished(worker, key) { outputOrFinished ->
184184
when (outputOrFinished) {
185185
is Output -> handler(outputOrFinished.value)
186-
Finished -> noop()
186+
Finished -> noAction()
187187
}
188188
}
189189

kotlin/workflow-core/src/main/java/com/squareup/workflow/WorkflowAction.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@ interface WorkflowAction<StateT, out OutputT : Any> : (StateT) -> Pair<StateT, O
4141
}
4242

4343
/**
44-
* Returns a [WorkflowAction] that does nothing.
44+
* Returns a [WorkflowAction] that does nothing: no output will be emitted, and `render` will be
45+
* called again with the same `state` as last time.
46+
*
47+
* Use this to, for example, ignore the output of a child workflow or worker.
4548
*/
46-
fun <StateT, OutputT : Any> noop(): WorkflowAction<StateT, OutputT> =
49+
fun <StateT, OutputT : Any> noAction(): WorkflowAction<StateT, OutputT> =
4750
WorkflowAction({ "noop" }) { Pair(it, null) }
4851

4952
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import com.squareup.workflow.StatefulWorkflow
2323
import com.squareup.workflow.Worker
2424
import com.squareup.workflow.Workflow
2525
import com.squareup.workflow.WorkflowAction.Companion.emitOutput
26-
import com.squareup.workflow.WorkflowAction.Companion.noop
26+
import com.squareup.workflow.WorkflowAction.Companion.noAction
2727
import com.squareup.workflow.internal.Behavior.WorkflowOutputCase
2828
import com.squareup.workflow.internal.RealRenderContext.Renderer
2929
import com.squareup.workflow.internal.RealRenderContextTest.TestRenderer.Rendering
@@ -88,7 +88,7 @@ class RealRenderContextTest {
8888

8989
@Test fun `make sink completes update`() {
9090
val context = RealRenderContext<String, String>(PoisonRenderer())
91-
val expectedUpdate = noop<String, String>()
91+
val expectedUpdate = noAction<String, String>()
9292
val handler = context.onEvent<String> { expectedUpdate }
9393
val behavior = context.buildBehavior()
9494
assertFalse(behavior.nextActionFromEvent.isCompleted)

kotlin/workflow-testing/src/test/java/com/squareup/workflow/WorkerCompositionIntegrationTest.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import com.squareup.workflow.Worker.OutputOrFinished.Finished
2222
import com.squareup.workflow.Worker.OutputOrFinished.Output
2323
import com.squareup.workflow.WorkflowAction.Companion.emitOutput
2424
import com.squareup.workflow.WorkflowAction.Companion.enterState
25-
import com.squareup.workflow.WorkflowAction.Companion.noop
25+
import com.squareup.workflow.WorkflowAction.Companion.noAction
2626
import com.squareup.workflow.testing.testFromStart
2727
import kotlinx.coroutines.CancellationException
2828
import kotlinx.coroutines.TimeoutCancellationException
@@ -42,7 +42,7 @@ class WorkerCompositionIntegrationTest {
4242
var started = false
4343
val worker = Worker.create<Unit> { started = true }
4444
val workflow = Workflow.stateless<Boolean, Nothing, Unit> { input ->
45-
if (input) onWorkerOutput(worker) { noop() }
45+
if (input) onWorkerOutput(worker) { noAction() }
4646
}
4747

4848
workflow.testFromStart(false) {
@@ -60,7 +60,7 @@ class WorkerCompositionIntegrationTest {
6060
}
6161
}
6262
val workflow = Workflow.stateless<Boolean, Nothing, Unit> { input ->
63-
if (input) onWorkerOutput(worker) { noop() }
63+
if (input) onWorkerOutput(worker) { noAction() }
6464
}
6565

6666
workflow.testFromStart(true) {
@@ -83,7 +83,7 @@ class WorkerCompositionIntegrationTest {
8383
}
8484
}
8585
val workflow = Workflow.stateless<Unit, Nothing, Unit> { _ ->
86-
onWorkerOutput(worker) { noop() }
86+
onWorkerOutput(worker) { noAction() }
8787
}
8888

8989
workflow.testFromStart {
@@ -113,7 +113,7 @@ class WorkerCompositionIntegrationTest {
113113
}
114114
}
115115
val workflow = Workflow.stateless<Boolean, Nothing, Unit> { input ->
116-
if (input) onWorkerOutput(worker) { noop() }
116+
if (input) onWorkerOutput(worker) { noAction() }
117117
}
118118

119119
workflow.testFromStart(false) {

0 commit comments

Comments
 (0)