From f68cf4361eac023dd8917b75de074b9bb6794695 Mon Sep 17 00:00:00 2001 From: Ray Ryan Date: Sun, 28 Jun 2020 18:19:01 -0700 Subject: [PATCH] Renames WorkflowAction.nextState to state Undoing a crime against nature and common sense. Closes #9 --- .../sample/poetryapp/PoemsBrowserWorkflow.kt | 2 +- .../hellobackbutton/AreYouSureWorkflow.kt | 4 +-- .../HelloBackButtonWorkflow.kt | 4 +-- .../sample/dungeon/DungeonAppWorkflow.kt | 6 ++-- .../sample/dungeon/GameSessionWorkflow.kt | 6 ++-- .../com/squareup/sample/dungeon/AiWorkflow.kt | 4 +-- .../squareup/sample/dungeon/GameWorkflow.kt | 4 +-- .../squareup/sample/dungeon/PlayerWorkflow.kt | 4 +-- .../shakeable/ShakeableTimeMachineWorkflow.kt | 6 ++-- .../timemachine/TimeMachineWorkflowTest.kt | 2 +- .../helloterminal/BlinkingCursorWorkflow.kt | 2 +- .../helloterminal/HelloTerminalWorkflow.kt | 4 +-- .../sample/hellotodo/EditTextWorkflow.kt | 12 ++++---- .../squareup/sample/hellotodo/TodoWorkflow.kt | 12 ++++---- .../helloworkflowfragment/HelloWorkflow.kt | 2 +- .../sample/helloworkflow/HelloWorkflow.kt | 2 +- .../sample/recyclerview/AppWorkflow.kt | 6 ++-- .../EditableListWorkflow.kt | 2 +- .../sample/authworkflow/AuthWorkflow.kt | 12 ++++---- .../sample/gameworkflow/RunGameWorkflow.kt | 28 +++++++++---------- .../sample/gameworkflow/TakeTurnsWorkflow.kt | 10 +++---- .../sample/todo/TodoListsAppWorkflow.kt | 10 +++---- workflow-core/api/workflow-core.api | 4 +-- .../com/squareup/workflow/StatefulWorkflow.kt | 4 +-- .../com/squareup/workflow/WorkflowAction.kt | 24 ++++++++-------- .../java/com/squareup/workflow/SinkTest.kt | 4 +-- .../squareup/workflow/WorkflowActionTest.kt | 18 ++++++------ .../squareup/workflow/RenderWorkflowInTest.kt | 6 ++-- .../workflow/internal/WorkflowNodeTest.kt | 8 +++--- .../workflow/internal/WorkflowRunnerTest.kt | 4 +-- .../com/squareup/workflow/TreeWorkflow.kt | 2 +- .../WorkerCompositionIntegrationTest.kt | 2 +- .../WorkflowCompositionIntegrationTest.kt | 2 +- .../workflow/testing/RealRenderTesterTest.kt | 8 +++--- .../tracing/TracingWorkflowInterceptor.kt | 6 ++-- 35 files changed, 118 insertions(+), 118 deletions(-) diff --git a/samples/containers/app-poetry/src/main/java/com/squareup/sample/poetryapp/PoemsBrowserWorkflow.kt b/samples/containers/app-poetry/src/main/java/com/squareup/sample/poetryapp/PoemsBrowserWorkflow.kt index 179dd90ba5..26d8c0676b 100644 --- a/samples/containers/app-poetry/src/main/java/com/squareup/sample/poetryapp/PoemsBrowserWorkflow.kt +++ b/samples/containers/app-poetry/src/main/java/com/squareup/sample/poetryapp/PoemsBrowserWorkflow.kt @@ -61,7 +61,7 @@ object PoemsBrowserWorkflow : } private fun choosePoem(index: SelectedPoem) = action("goToPoem") { - nextState = index + state = index } private val clearSelection = choosePoem(-1) diff --git a/samples/containers/hello-back-button/src/main/java/com/squareup/sample/hellobackbutton/AreYouSureWorkflow.kt b/samples/containers/hello-back-button/src/main/java/com/squareup/sample/hellobackbutton/AreYouSureWorkflow.kt index 8de2b3d02e..8f419c7ee6 100644 --- a/samples/containers/hello-back-button/src/main/java/com/squareup/sample/hellobackbutton/AreYouSureWorkflow.kt +++ b/samples/containers/hello-back-button/src/main/java/com/squareup/sample/hellobackbutton/AreYouSureWorkflow.kt @@ -95,7 +95,7 @@ object AreYouSureWorkflow : StatefulWorkflow Baker Baker -> Charlie Charlie -> Able @@ -66,7 +66,7 @@ object HelloBackButtonWorkflow : StatefulWorkflow throw IllegalStateException() Baker -> Able Charlie -> Baker diff --git a/samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/DungeonAppWorkflow.kt b/samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/DungeonAppWorkflow.kt index 3defec6b2d..7e53c5cdfc 100644 --- a/samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/DungeonAppWorkflow.kt +++ b/samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/DungeonAppWorkflow.kt @@ -80,12 +80,12 @@ class DungeonAppWorkflow( override fun snapshotState(state: State): Snapshot = Snapshot.EMPTY private fun displayBoards(boards: Map) = action { - nextState = ChoosingBoard(boards.toList()) + state = ChoosingBoard(boards.toList()) } private fun selectBoard(index: Int) = action { // No-op if we're not in the ChoosingBoard state. - val boards = (nextState as? ChoosingBoard)?.boards ?: return@action - nextState = PlayingGame(boards[index].first) + val boards = (state as? ChoosingBoard)?.boards ?: return@action + state = PlayingGame(boards[index].first) } } diff --git a/samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/GameSessionWorkflow.kt b/samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/GameSessionWorkflow.kt index c1ebbea6ee..6db07225c2 100644 --- a/samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/GameSessionWorkflow.kt +++ b/samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/GameSessionWorkflow.kt @@ -100,7 +100,7 @@ class GameSessionWorkflow( private class StartRunning(val board: Board) : WorkflowAction { override fun Updater.apply() { - nextState = Running(board) + state = Running(board) } } @@ -111,7 +111,7 @@ class GameSessionWorkflow( when (output) { Vibrate -> vibrate(50) PlayerWasEaten -> { - nextState = GameOver(board) + state = GameOver(board) vibrate(20) vibrate(20) vibrate(20) @@ -121,7 +121,7 @@ class GameSessionWorkflow( } } - private fun restartGame() = action("restartGame") { nextState = Loading } + private fun restartGame() = action("restartGame") { state = Loading } private fun vibrate(durationMs: Long) { @Suppress("DEPRECATION") diff --git a/samples/dungeon/common/src/main/java/com/squareup/sample/dungeon/AiWorkflow.kt b/samples/dungeon/common/src/main/java/com/squareup/sample/dungeon/AiWorkflow.kt index bdaadac05b..8ce1fe2e5f 100644 --- a/samples/dungeon/common/src/main/java/com/squareup/sample/dungeon/AiWorkflow.kt +++ b/samples/dungeon/common/src/main/java/com/squareup/sample/dungeon/AiWorkflow.kt @@ -78,14 +78,14 @@ class AiWorkflow( private val updateDirection = action("updateDirection") { // Rotate 90 degrees. - val newDirection = when (nextState.direction) { + val newDirection = when (state.direction) { UP -> RIGHT RIGHT -> DOWN DOWN -> LEFT LEFT -> UP } - nextState = nextState.copy(direction = newDirection) + state = state.copy(direction = newDirection) } } diff --git a/samples/dungeon/common/src/main/java/com/squareup/sample/dungeon/GameWorkflow.kt b/samples/dungeon/common/src/main/java/com/squareup/sample/dungeon/GameWorkflow.kt index a76f8a7823..9ec49408e7 100644 --- a/samples/dungeon/common/src/main/java/com/squareup/sample/dungeon/GameWorkflow.kt +++ b/samples/dungeon/common/src/main/java/com/squareup/sample/dungeon/GameWorkflow.kt @@ -192,10 +192,10 @@ class GameWorkflow( // Check if AI captured player. if (newGame.isPlayerEaten) { - nextState = nextState.copy(game = newGame) + state = state.copy(game = newGame) setOutput(PlayerWasEaten) } else { - nextState = nextState.copy(game = newGame) + state = state.copy(game = newGame) output?.let { setOutput(it) } } } diff --git a/samples/dungeon/common/src/main/java/com/squareup/sample/dungeon/PlayerWorkflow.kt b/samples/dungeon/common/src/main/java/com/squareup/sample/dungeon/PlayerWorkflow.kt index 4ddb4ce65b..ef66a3eb6d 100644 --- a/samples/dungeon/common/src/main/java/com/squareup/sample/dungeon/PlayerWorkflow.kt +++ b/samples/dungeon/common/src/main/java/com/squareup/sample/dungeon/PlayerWorkflow.kt @@ -39,13 +39,13 @@ class PlayerWorkflow( class StartMoving(private val direction: Direction) : Action() { override fun Updater.apply() { - nextState += direction + state += direction } } class StopMoving(private val direction: Direction) : Action() { override fun Updater.apply() { - nextState -= direction + state -= direction } } } diff --git a/samples/dungeon/timemachine-shakeable/src/main/java/com/squareup/sample/timemachine/shakeable/ShakeableTimeMachineWorkflow.kt b/samples/dungeon/timemachine-shakeable/src/main/java/com/squareup/sample/timemachine/shakeable/ShakeableTimeMachineWorkflow.kt index fe2711defc..7d8b48ef90 100644 --- a/samples/dungeon/timemachine-shakeable/src/main/java/com/squareup/sample/timemachine/shakeable/ShakeableTimeMachineWorkflow.kt +++ b/samples/dungeon/timemachine-shakeable/src/main/java/com/squareup/sample/timemachine/shakeable/ShakeableTimeMachineWorkflow.kt @@ -118,20 +118,20 @@ class ShakeableTimeMachineWorkflow( } private val onShake = action { - nextState = PlayingBack(Duration.INFINITE) + state = PlayingBack(Duration.INFINITE) } private inner class SeekAction( private val newPosition: Duration ) : WorkflowAction { override fun Updater.apply() { - nextState = PlayingBack(newPosition) + state = PlayingBack(newPosition) } } private inner class ResumeRecordingAction : WorkflowAction { override fun Updater.apply() { - nextState = Recording + state = Recording } } diff --git a/samples/dungeon/timemachine/src/test/java/com/squareup/sample/timemachine/TimeMachineWorkflowTest.kt b/samples/dungeon/timemachine/src/test/java/com/squareup/sample/timemachine/TimeMachineWorkflowTest.kt index 33b8010162..88429bfddf 100644 --- a/samples/dungeon/timemachine/src/test/java/com/squareup/sample/timemachine/TimeMachineWorkflowTest.kt +++ b/samples/dungeon/timemachine/src/test/java/com/squareup/sample/timemachine/TimeMachineWorkflowTest.kt @@ -42,7 +42,7 @@ class TimeMachineWorkflowTest { val delegateWorkflow = Workflow.stateful( initialState = "initial", render = { state -> - val sink: Sink = makeEventSink { nextState = it } + val sink: Sink = makeEventSink { this.state = it } DelegateRendering(state, setState = { sink.send(it) }) } ) diff --git a/samples/hello-terminal/hello-terminal-app/src/main/java/com/squareup/sample/helloterminal/BlinkingCursorWorkflow.kt b/samples/hello-terminal/hello-terminal-app/src/main/java/com/squareup/sample/helloterminal/BlinkingCursorWorkflow.kt index 3c98e1a146..06c3d5b85d 100644 --- a/samples/hello-terminal/hello-terminal-app/src/main/java/com/squareup/sample/helloterminal/BlinkingCursorWorkflow.kt +++ b/samples/hello-terminal/hello-terminal-app/src/main/java/com/squareup/sample/helloterminal/BlinkingCursorWorkflow.kt @@ -59,6 +59,6 @@ class BlinkingCursorWorkflow( override fun snapshotState(state: Boolean): Snapshot = Snapshot.EMPTY private fun setCursorShowing(showing: Boolean) = action { - nextState = showing + state = showing } } diff --git a/samples/hello-terminal/hello-terminal-app/src/main/java/com/squareup/sample/helloterminal/HelloTerminalWorkflow.kt b/samples/hello-terminal/hello-terminal-app/src/main/java/com/squareup/sample/helloterminal/HelloTerminalWorkflow.kt index 682146039f..08d3ac121d 100644 --- a/samples/hello-terminal/hello-terminal-app/src/main/java/com/squareup/sample/helloterminal/HelloTerminalWorkflow.kt +++ b/samples/hello-terminal/hello-terminal-app/src/main/java/com/squareup/sample/helloterminal/HelloTerminalWorkflow.kt @@ -79,8 +79,8 @@ class HelloTerminalWorkflow : TerminalWorkflow, private fun onKeystroke(key: KeyStroke): HelloTerminalAction = action { when { key.character == 'Q' -> setOutput(0) - key.keyType == Backspace -> nextState = nextState.backspace() - key.character != null -> nextState = nextState.append(key.character!!) + key.keyType == Backspace -> state = state.backspace() + key.character != null -> state = state.append(key.character!!) } } } diff --git a/samples/hello-terminal/todo-terminal-app/src/main/java/com/squareup/sample/hellotodo/EditTextWorkflow.kt b/samples/hello-terminal/todo-terminal-app/src/main/java/com/squareup/sample/hellotodo/EditTextWorkflow.kt index 964244842b..90bc6907b0 100644 --- a/samples/hello-terminal/todo-terminal-app/src/main/java/com/squareup/sample/hellotodo/EditTextWorkflow.kt +++ b/samples/hello-terminal/todo-terminal-app/src/main/java/com/squareup/sample/hellotodo/EditTextWorkflow.kt @@ -67,18 +67,18 @@ class EditTextWorkflow : StatefulWorkflow { - nextState = moveCursor(props, nextState, 1) - props.text.insertCharAt(nextState.cursorPosition, key.character!!) + state = moveCursor(props, state, 1) + props.text.insertCharAt(state.cursorPosition, key.character!!) } Backspace -> { if (props.text.isNotEmpty()) { - nextState = moveCursor(props, nextState, -1) - props.text.removeRange(nextState.cursorPosition - 1, nextState.cursorPosition) + state = moveCursor(props, state, -1) + props.text.removeRange(state.cursorPosition - 1, state.cursorPosition) } } - ArrowLeft -> nextState = moveCursor(props, nextState, -1) - ArrowRight -> nextState = moveCursor(props, nextState, 1) + ArrowLeft -> state = moveCursor(props, state, -1) + ArrowRight -> state = moveCursor(props, state, 1) else -> { // Nothing to do. } diff --git a/samples/hello-terminal/todo-terminal-app/src/main/java/com/squareup/sample/hellotodo/TodoWorkflow.kt b/samples/hello-terminal/todo-terminal-app/src/main/java/com/squareup/sample/hellotodo/TodoWorkflow.kt index 0289d09fb2..6d76951be1 100644 --- a/samples/hello-terminal/todo-terminal-app/src/main/java/com/squareup/sample/hellotodo/TodoWorkflow.kt +++ b/samples/hello-terminal/todo-terminal-app/src/main/java/com/squareup/sample/hellotodo/TodoWorkflow.kt @@ -93,24 +93,24 @@ class TodoWorkflow : TerminalWorkflow, private fun onKeystroke(key: KeyStroke) = action { @Suppress("NON_EXHAUSTIVE_WHEN") when (key.keyType) { - ArrowUp -> nextState = nextState.moveFocusUp() - ArrowDown -> nextState = nextState.moveFocusDown() - Enter -> if (nextState.focusedField > TITLE_FIELD_INDEX) { - nextState = nextState.toggleChecked(nextState.focusedField) + ArrowUp -> state = state.moveFocusUp() + ArrowDown -> state = state.moveFocusDown() + Enter -> if (state.focusedField > TITLE_FIELD_INDEX) { + state = state.toggleChecked(state.focusedField) } } } } private fun updateTitle(newTitle: String): TodoAction = action { - nextState = nextState.copy(title = newTitle) + state = state.copy(title = newTitle) } private fun setLabel( index: Int, text: String ): TodoAction = action { - nextState = nextState.copy(items = nextState.items.mapIndexed { i, item -> + state = state.copy(items = state.items.mapIndexed { i, item -> if (index == i) item.copy(label = text) else item }) } diff --git a/samples/hello-workflow-fragment/src/main/java/com/squareup/sample/helloworkflowfragment/HelloWorkflow.kt b/samples/hello-workflow-fragment/src/main/java/com/squareup/sample/helloworkflowfragment/HelloWorkflow.kt index d60626c5e5..664b270c83 100644 --- a/samples/hello-workflow-fragment/src/main/java/com/squareup/sample/helloworkflowfragment/HelloWorkflow.kt +++ b/samples/hello-workflow-fragment/src/main/java/com/squareup/sample/helloworkflowfragment/HelloWorkflow.kt @@ -56,7 +56,7 @@ object HelloWorkflow : StatefulWorkflow() { override fun snapshotState(state: State): Snapshot = Snapshot.of(if (state == Hello) 1 else 0) private val helloAction = action { - nextState = when (nextState) { + state = when (state) { Hello -> Goodbye Goodbye -> Hello } diff --git a/samples/hello-workflow/src/main/java/com/squareup/sample/helloworkflow/HelloWorkflow.kt b/samples/hello-workflow/src/main/java/com/squareup/sample/helloworkflow/HelloWorkflow.kt index 958cf92125..ef569bc0b5 100644 --- a/samples/hello-workflow/src/main/java/com/squareup/sample/helloworkflow/HelloWorkflow.kt +++ b/samples/hello-workflow/src/main/java/com/squareup/sample/helloworkflow/HelloWorkflow.kt @@ -56,7 +56,7 @@ object HelloWorkflow : StatefulWorkflow() { override fun snapshotState(state: State): Snapshot = Snapshot.of(if (state == Hello) 1 else 0) private val helloAction = action { - nextState = when (nextState) { + state = when (state) { Hello -> Goodbye Goodbye -> Hello } diff --git a/samples/recyclerview/src/main/java/com/squareup/sample/recyclerview/AppWorkflow.kt b/samples/recyclerview/src/main/java/com/squareup/sample/recyclerview/AppWorkflow.kt index 34fb8417e4..64d266e921 100644 --- a/samples/recyclerview/src/main/java/com/squareup/sample/recyclerview/AppWorkflow.kt +++ b/samples/recyclerview/src/main/java/com/squareup/sample/recyclerview/AppWorkflow.kt @@ -79,9 +79,9 @@ object AppWorkflow : StatefulWorkflow() { data class CommitNewRowAction(val index: Int) : Action() override fun Updater.apply() { - nextState = when (this@Action) { - ShowAddRowAction -> ChooseNewRow(nextState.rows) - is CommitNewRowAction -> ShowList(nextState.rows + allRowTypes[index]) + state = when (this@Action) { + ShowAddRowAction -> ChooseNewRow(state.rows) + is CommitNewRowAction -> ShowList(state.rows + allRowTypes[index]) } } } diff --git a/samples/recyclerview/src/main/java/com/squareup/sample/recyclerview/editablelistworkflow/EditableListWorkflow.kt b/samples/recyclerview/src/main/java/com/squareup/sample/recyclerview/editablelistworkflow/EditableListWorkflow.kt index 969d5be0d8..f4389104aa 100644 --- a/samples/recyclerview/src/main/java/com/squareup/sample/recyclerview/editablelistworkflow/EditableListWorkflow.kt +++ b/samples/recyclerview/src/main/java/com/squareup/sample/recyclerview/editablelistworkflow/EditableListWorkflow.kt @@ -77,7 +77,7 @@ object EditableListWorkflow : StatefulWorkflow position: Int, newValue: Any? ) = action { - nextState = nextState.copy(rowValues = nextState.rowValues.mapIndexed { index, value -> + state = state.copy(rowValues = state.rowValues.mapIndexed { index, value -> if (index == position) value.withValue(newValue) else value }) } diff --git a/samples/tictactoe/common/src/main/java/com/squareup/sample/authworkflow/AuthWorkflow.kt b/samples/tictactoe/common/src/main/java/com/squareup/sample/authworkflow/AuthWorkflow.kt index eb3823a079..0ca6c643ad 100644 --- a/samples/tictactoe/common/src/main/java/com/squareup/sample/authworkflow/AuthWorkflow.kt +++ b/samples/tictactoe/common/src/main/java/com/squareup/sample/authworkflow/AuthWorkflow.kt @@ -94,7 +94,7 @@ internal sealed class Action : WorkflowAction { final override fun Updater.apply() { when (this@Action) { is SubmitLogin -> { - nextState = when { + state = when { email.isValidEmail -> Authorizing(email, password) else -> LoginPrompt(email.emailValidationErrorMessage) } @@ -104,20 +104,20 @@ internal sealed class Action : WorkflowAction { is HandleAuthResponse -> { when { - response.isLoginFailure -> nextState = LoginPrompt(response.errorMessage) - response.twoFactorRequired -> nextState = SecondFactorPrompt(response.token) + response.isLoginFailure -> state = LoginPrompt(response.errorMessage) + response.twoFactorRequired -> state = SecondFactorPrompt(response.token) else -> setOutput(Authorized(response.token)) } } - is SubmitSecondFactor -> nextState = AuthorizingSecondFactor(tempToken, secondFactor) + is SubmitSecondFactor -> state = AuthorizingSecondFactor(tempToken, secondFactor) - CancelSecondFactor -> nextState = LoginPrompt() + CancelSecondFactor -> state = LoginPrompt() is HandleSecondFactorResponse -> { when { response.isSecondFactorFailure -> - nextState = SecondFactorPrompt(tempToken, response.errorMessage) + state = SecondFactorPrompt(tempToken, response.errorMessage) else -> setOutput(Authorized(response.token)) } } diff --git a/samples/tictactoe/common/src/main/java/com/squareup/sample/gameworkflow/RunGameWorkflow.kt b/samples/tictactoe/common/src/main/java/com/squareup/sample/gameworkflow/RunGameWorkflow.kt index 63c6201ce1..890aa418d4 100644 --- a/samples/tictactoe/common/src/main/java/com/squareup/sample/gameworkflow/RunGameWorkflow.kt +++ b/samples/tictactoe/common/src/main/java/com/squareup/sample/gameworkflow/RunGameWorkflow.kt @@ -104,50 +104,50 @@ sealed class Action : WorkflowAction { when (this@Action) { CancelNewGame -> setOutput(CanceledStart) - is StartGame -> nextState = Playing(PlayerInfo(x, o)) + is StartGame -> state = Playing(PlayerInfo(x, o)) is StopPlaying -> { - val oldState = nextState as Playing - nextState = when (game.ending) { + val oldState = state as Playing + state = when (game.ending) { Quitted -> MaybeQuitting(oldState.playerInfo, game) else -> GameOver(oldState.playerInfo, game) } } ConfirmQuit -> { - val oldState = nextState as MaybeQuitting - nextState = MaybeQuittingForSure(oldState.playerInfo, oldState.completedGame) + val oldState = state as MaybeQuitting + state = MaybeQuittingForSure(oldState.playerInfo, oldState.completedGame) } is ContinuePlaying -> { - nextState = Playing(playerInfo, turn) + state = Playing(playerInfo, turn) } ConfirmQuitAgain -> { - val oldState = nextState as MaybeQuittingForSure - nextState = GameOver(oldState.playerInfo, oldState.completedGame) + val oldState = state as MaybeQuittingForSure + state = GameOver(oldState.playerInfo, oldState.completedGame) } is HandleLogGame -> { - val oldState = nextState as GameOver - nextState = when (result) { + val oldState = state as GameOver + state = when (result) { TRY_LATER -> oldState.copy(syncState = SAVE_FAILED) LOGGED -> oldState.copy(syncState = SAVED) } } TrySaveAgain -> { - val oldState = nextState as GameOver + val oldState = state as GameOver check(oldState.syncState == SAVE_FAILED) { "Should only receive $TrySaveAgain in syncState $SAVE_FAILED, " + "was ${oldState.syncState}" } - nextState = oldState.copy(syncState = SAVING) + state = oldState.copy(syncState = SAVING) } PlayAgain -> { - val (x, o) = (nextState as GameOver).playerInfo - nextState = NewGame(x, o) + val (x, o) = (state as GameOver).playerInfo + state = NewGame(x, o) } Exit -> setOutput(FinishedPlaying) diff --git a/samples/tictactoe/common/src/main/java/com/squareup/sample/gameworkflow/TakeTurnsWorkflow.kt b/samples/tictactoe/common/src/main/java/com/squareup/sample/gameworkflow/TakeTurnsWorkflow.kt index ca641b9e7e..038660e605 100644 --- a/samples/tictactoe/common/src/main/java/com/squareup/sample/gameworkflow/TakeTurnsWorkflow.kt +++ b/samples/tictactoe/common/src/main/java/com/squareup/sample/gameworkflow/TakeTurnsWorkflow.kt @@ -58,22 +58,22 @@ class RealTakeTurnsWorkflow : TakeTurnsWorkflow, private val col: Int ) : Action() { override fun Updater.apply() { - val newBoard = nextState.board.takeSquare(row, col, nextState.playing) + val newBoard = state.board.takeSquare(row, col, state.playing) when { newBoard.hasVictory() -> - setOutput(CompletedGame(Victory, nextState.copy(board = newBoard))) + setOutput(CompletedGame(Victory, state.copy(board = newBoard))) - newBoard.isFull() -> setOutput(CompletedGame(Draw, nextState.copy(board = newBoard))) + newBoard.isFull() -> setOutput(CompletedGame(Draw, state.copy(board = newBoard))) - else -> nextState = Turn(playing = nextState.playing.other, board = newBoard) + else -> state = Turn(playing = state.playing.other, board = newBoard) } } } object Quit : Action() { override fun Updater.apply() { - setOutput(CompletedGame(Quitted, nextState)) + setOutput(CompletedGame(Quitted, state)) } } } diff --git a/samples/todo-android/common/src/main/java/com/squareup/sample/todo/TodoListsAppWorkflow.kt b/samples/todo-android/common/src/main/java/com/squareup/sample/todo/TodoListsAppWorkflow.kt index 3f03e16b66..975f0964cd 100644 --- a/samples/todo-android/common/src/main/java/com/squareup/sample/todo/TodoListsAppWorkflow.kt +++ b/samples/todo-android/common/src/main/java/com/squareup/sample/todo/TodoListsAppWorkflow.kt @@ -62,18 +62,18 @@ object TodoListsAppWorkflow : private val editorWorkflow = TodoEditorWorkflow() private fun onListSelected(index: Int): TodoListsAction = action { - nextState = EditingList(nextState.lists, index) + state = EditingList(state.lists, index) } private fun onEditOutput(output: TodoEditorOutput): TodoListsAction = action { - nextState = when (output) { + state = when (output) { is ListUpdated -> { - val oldState = nextState as EditingList + val oldState = state as EditingList oldState.copy( - lists = nextState.lists.updateRow(oldState.editingIndex, output.newList) + lists = state.lists.updateRow(oldState.editingIndex, output.newList) ) } - Done -> ShowingLists(nextState.lists) + Done -> ShowingLists(state.lists) } } diff --git a/workflow-core/api/workflow-core.api b/workflow-core/api/workflow-core.api index 055bc8e412..e1a60bfe2b 100644 --- a/workflow-core/api/workflow-core.api +++ b/workflow-core/api/workflow-core.api @@ -213,9 +213,9 @@ public final class com/squareup/workflow/WorkflowAction$Mutator { public final class com/squareup/workflow/WorkflowAction$Updater { public fun (Ljava/lang/Object;)V - public final fun getNextState ()Ljava/lang/Object; - public final fun setNextState (Ljava/lang/Object;)V + public final fun getState ()Ljava/lang/Object; public final fun setOutput (Ljava/lang/Object;)V + public final fun setState (Ljava/lang/Object;)V } public final class com/squareup/workflow/WorkflowActionKt { diff --git a/workflow-core/src/main/java/com/squareup/workflow/StatefulWorkflow.kt b/workflow-core/src/main/java/com/squareup/workflow/StatefulWorkflow.kt index 8ca5cd1f9c..c51217c4c1 100644 --- a/workflow-core/src/main/java/com/squareup/workflow/StatefulWorkflow.kt +++ b/workflow-core/src/main/java/com/squareup/workflow/StatefulWorkflow.kt @@ -276,7 +276,7 @@ fun @Deprecated( message = "Use action", replaceWith = ReplaceWith( - expression = "action(name) { nextState = state }", + expression = "action(name) { state = state }", imports = arrayOf("com.squareup.workflow.action") ) ) @@ -290,7 +290,7 @@ fun @Deprecated( message = "Use action", replaceWith = ReplaceWith( - expression = "action(name) { nextState = state }", + expression = "action(name) { state = state }", imports = arrayOf("com.squareup.workflow.action") ) ) 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 a6fcf48546..fd54eed1b6 100644 --- a/workflow-core/src/main/java/com/squareup/workflow/WorkflowAction.kt +++ b/workflow-core/src/main/java/com/squareup/workflow/WorkflowAction.kt @@ -27,11 +27,11 @@ interface WorkflowAction { /** * The context for calls to [WorkflowAction.apply]. Allows the action to set the - * [nextState], and to emit the [setOutput]. + * [state], and to emit the [setOutput]. * - * @param nextState the state that the workflow should move to. Default is the current state. + * @param state the state that the workflow should move to. Default is the current state. */ - class Updater(var nextState: S) { + class Updater(var state: S) { internal var output: WorkflowOutput<@UnsafeVariance O>? = null private set @@ -50,10 +50,10 @@ interface WorkflowAction { */ @Suppress("DEPRECATION") fun Updater.apply() { - val mutator = Mutator(nextState) + val mutator = Mutator(state) mutator.apply() ?.let { setOutput(it) } - nextState = mutator.state + state = mutator.state } @Suppress("DEPRECATION") @@ -80,7 +80,7 @@ interface WorkflowAction { @Deprecated( message = "Use action", replaceWith = ReplaceWith( - expression = "action { nextState = newState }", + expression = "action { state = newState }", imports = arrayOf("com.squareup.workflow.action") ) ) @@ -89,7 +89,7 @@ interface WorkflowAction { emittingOutput: OutputT? = null ): WorkflowAction = action({ "enterState($newState, $emittingOutput)" }) { - nextState = newState + state = newState emittingOutput?.let { setOutput(it) } } @@ -100,7 +100,7 @@ interface WorkflowAction { @Deprecated( message = "Use action", replaceWith = ReplaceWith( - expression = "action { nextState = newState }", + expression = "action { state = newState }", imports = arrayOf("com.squareup.workflow.action") ) ) @@ -110,7 +110,7 @@ interface WorkflowAction { emittingOutput: OutputT? = null ): WorkflowAction = action({ "enterState($name, $newState, $emittingOutput)" }) { - nextState = newState + state = newState emittingOutput?.let { setOutput(it) } } @@ -120,7 +120,7 @@ interface WorkflowAction { @Deprecated( message = "Use action", replaceWith = ReplaceWith( - expression = "action(name) { nextState = state }", + expression = "action(name) { state = state }", imports = arrayOf("com.squareup.workflow.action") ) ) @@ -130,7 +130,7 @@ interface WorkflowAction { modify: (StateT) -> StateT ): WorkflowAction = action({ "modifyState(${name()}, $emittingOutput)" }) { - nextState = modify(nextState) + state = modify(state) emittingOutput?.let { setOutput(it) } } @@ -213,7 +213,7 @@ fun WorkflowAction.applyTo( ): Pair?> { val updater = Updater(state) updater.apply() - return Pair(updater.nextState, updater.output) + return Pair(updater.state, updater.output) } /** Wrapper around a potentially-nullable [OutputT] value. */ diff --git a/workflow-core/src/test/java/com/squareup/workflow/SinkTest.kt b/workflow-core/src/test/java/com/squareup/workflow/SinkTest.kt index 7bfc689125..3309b82ece 100644 --- a/workflow-core/src/test/java/com/squareup/workflow/SinkTest.kt +++ b/workflow-core/src/test/java/com/squareup/workflow/SinkTest.kt @@ -41,7 +41,7 @@ class SinkTest { val collector = launch { flow.collectToSink(sink) { action { - nextState = "$nextState $it" + state = "$state $it" setOutput("output: $it") } } @@ -75,7 +75,7 @@ class SinkTest { var applications = 0 val action = action { applications++ - nextState = "$nextState applied" + state = "$state applied" setOutput("output") } diff --git a/workflow-core/src/test/java/com/squareup/workflow/WorkflowActionTest.kt b/workflow-core/src/test/java/com/squareup/workflow/WorkflowActionTest.kt index abb959cc2e..ceafb0e6a6 100644 --- a/workflow-core/src/test/java/com/squareup/workflow/WorkflowActionTest.kt +++ b/workflow-core/src/test/java/com/squareup/workflow/WorkflowActionTest.kt @@ -27,23 +27,23 @@ class WorkflowActionTest { @Test fun `applyTo works when no output is set`() { val action = object : WorkflowAction { override fun Updater.apply() { - nextState = "nextState: $nextState" + state = "state: $state" } } - val (nextState, output) = action.applyTo("state") - assertEquals("nextState: state", nextState) + val (state, output) = action.applyTo("state") + assertEquals("state: state", state) assertNull(output) } @Test fun `applyTo works when null output is set`() { val action = object : WorkflowAction { override fun Updater.apply() { - nextState = "nextState: $nextState" + state = "state: $state" setOutput(null) } } - val (nextState, output) = action.applyTo("state") - assertEquals("nextState: state", nextState) + val (state, output) = action.applyTo("state") + assertEquals("state: state", state) assertNotNull(output) assertNull(output.value) } @@ -51,12 +51,12 @@ class WorkflowActionTest { @Test fun `applyTo works when non-null output is set`() { val action = object : WorkflowAction { override fun Updater.apply() { - nextState = "nextState: $nextState" + state = "state: $state" setOutput("output") } } - val (nextState, output) = action.applyTo("state") - assertEquals("nextState: state", nextState) + val (state, output) = action.applyTo("state") + assertEquals("state: state", state) assertNotNull(output) assertEquals("output", output.value) } diff --git a/workflow-runtime/src/test/java/com/squareup/workflow/RenderWorkflowInTest.kt b/workflow-runtime/src/test/java/com/squareup/workflow/RenderWorkflowInTest.kt index cb06bdd98d..d4c6fbb3ae 100644 --- a/workflow-runtime/src/test/java/com/squareup/workflow/RenderWorkflowInTest.kt +++ b/workflow-runtime/src/test/java/com/squareup/workflow/RenderWorkflowInTest.kt @@ -113,7 +113,7 @@ class RenderWorkflowInTest { render = { _, state -> Pair( state, - { newState -> actionSink.send(action { nextState = newState }) } + { newState -> actionSink.send(action { this.state = newState }) } ) } ) @@ -231,7 +231,7 @@ class RenderWorkflowInTest { val workflow = Workflow.stateful( initialState = { false }, render = { _, throwNow -> - runningWorker(Worker.from { trigger.await() }) { action { nextState = true } } + runningWorker(Worker.from { trigger.await() }) { action { state = true } } if (throwNow) { throw ExpectedException() } @@ -374,7 +374,7 @@ class RenderWorkflowInTest { runningWorker(Worker.from { outputTrigger.await() }) { output -> action { setOutput(output) - nextState = output + this.state = output } } return@stateful state 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 966b3b29f6..ea0c0f2b2a 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 @@ -378,7 +378,7 @@ class WorkflowNodeTest { } val finish = action { - nextState = "finished" + state = "finished" } override fun render( @@ -1305,7 +1305,7 @@ class WorkflowNodeTest { initialState = { "initial" }, render = { _, state -> state to actionSink.contraMap { - action { nextState = "$nextState->$it" } + action { this.state = "${this.state}->$it" } } } ) @@ -1384,7 +1384,7 @@ class WorkflowNodeTest { val workflow = Workflow.stateful( initialState = { "initial" }, render = { _, state -> - runningWorker(Worker.from { "hello" }) { action { nextState = "$nextState->$it" } } + runningWorker(Worker.from { "hello" }) { action { this.state = "${this.state}->$it" } } return@stateful state } ) @@ -1457,7 +1457,7 @@ class WorkflowNodeTest { val workflow = Workflow.stateful( initialState = { "initial" }, render = { _, state -> - renderChild(child) { action { nextState = "$nextState->$it" } } + renderChild(child) { action { this.state = "${this.state}->$it" } } return@stateful state } ) diff --git a/workflow-runtime/src/test/java/com/squareup/workflow/internal/WorkflowRunnerTest.kt b/workflow-runtime/src/test/java/com/squareup/workflow/internal/WorkflowRunnerTest.kt index 9d435beb0f..5df727fa0d 100644 --- a/workflow-runtime/src/test/java/com/squareup/workflow/internal/WorkflowRunnerTest.kt +++ b/workflow-runtime/src/test/java/com/squareup/workflow/internal/WorkflowRunnerTest.kt @@ -111,7 +111,7 @@ class WorkflowRunnerTest { render = { _, state -> runningWorker(Worker.from { "work" }) { action { - nextState = "state: $it" + this.state = "state: $it" setOutput("output: $it") } } @@ -138,7 +138,7 @@ class WorkflowRunnerTest { render = { props, state -> runningWorker(Worker.from { "work" }) { action { - nextState = "state: $it" + this.state = "state: $it" setOutput("output: $it") } } diff --git a/workflow-testing/src/test/java/com/squareup/workflow/TreeWorkflow.kt b/workflow-testing/src/test/java/com/squareup/workflow/TreeWorkflow.kt index 689c69e4bb..7b9f083bc7 100644 --- a/workflow-testing/src/test/java/com/squareup/workflow/TreeWorkflow.kt +++ b/workflow-testing/src/test/java/com/squareup/workflow/TreeWorkflow.kt @@ -75,6 +75,6 @@ internal class TreeWorkflow( } private fun onEvent(newState: String) = action { - nextState = newState + state = newState } } diff --git a/workflow-testing/src/test/java/com/squareup/workflow/WorkerCompositionIntegrationTest.kt b/workflow-testing/src/test/java/com/squareup/workflow/WorkerCompositionIntegrationTest.kt index dce6fe8760..7b38f213cb 100644 --- a/workflow-testing/src/test/java/com/squareup/workflow/WorkerCompositionIntegrationTest.kt +++ b/workflow-testing/src/test/java/com/squareup/workflow/WorkerCompositionIntegrationTest.kt @@ -197,7 +197,7 @@ class WorkerCompositionIntegrationTest { val triggerOutput = WorkerSink("") val incrementState = action { - nextState += 1 + state += 1 } val workflow = Workflow.stateful Unit>( diff --git a/workflow-testing/src/test/java/com/squareup/workflow/WorkflowCompositionIntegrationTest.kt b/workflow-testing/src/test/java/com/squareup/workflow/WorkflowCompositionIntegrationTest.kt index 60a50a3487..4c25bc7eb1 100644 --- a/workflow-testing/src/test/java/com/squareup/workflow/WorkflowCompositionIntegrationTest.kt +++ b/workflow-testing/src/test/java/com/squareup/workflow/WorkflowCompositionIntegrationTest.kt @@ -107,7 +107,7 @@ class WorkflowCompositionIntegrationTest { runningWorker(triggerChildOutput) { action { setOutput(Unit) } } } val incrementState = action { - nextState += 1 + state += 1 } val workflow = Workflow.stateful Unit>( initialState = 0, diff --git a/workflow-testing/src/test/java/com/squareup/workflow/testing/RealRenderTesterTest.kt b/workflow-testing/src/test/java/com/squareup/workflow/testing/RealRenderTesterTest.kt index 5f3436814f..bb0cf68723 100644 --- a/workflow-testing/src/test/java/com/squareup/workflow/testing/RealRenderTesterTest.kt +++ b/workflow-testing/src/test/java/com/squareup/workflow/testing/RealRenderTesterTest.kt @@ -694,7 +694,7 @@ class RealRenderTesterTest { @Test fun `verifyActionResult works`() { class TestAction : WorkflowAction { override fun Updater.apply() { - nextState = "new state" + state = "new state" setOutput("output") } } @@ -717,7 +717,7 @@ class RealRenderTesterTest { @Test fun `verifyActionState and verifyActionOutput chain`() { class TestAction : WorkflowAction { override fun Updater.apply() { - nextState = "new state" + state = "new state" setOutput("output") } } @@ -739,7 +739,7 @@ class RealRenderTesterTest { @Test fun `verifyActionState and verifyNoActionOutput chain`() { class TestAction : WorkflowAction { override fun Updater.apply() { - nextState = "new state" + state = "new state" } } @@ -775,7 +775,7 @@ class RealRenderTesterTest { @Test fun `verifyActionState handles new state`() { class TestAction : WorkflowAction { override fun Updater.apply() { - nextState = "new state" + state = "new state" } } diff --git a/workflow-tracing/src/main/java/com/squareup/workflow/diagnostic/tracing/TracingWorkflowInterceptor.kt b/workflow-tracing/src/main/java/com/squareup/workflow/diagnostic/tracing/TracingWorkflowInterceptor.kt index d9c419be80..37ceb3f480 100644 --- a/workflow-tracing/src/main/java/com/squareup/workflow/diagnostic/tracing/TracingWorkflowInterceptor.kt +++ b/workflow-tracing/src/main/java/com/squareup/workflow/diagnostic/tracing/TracingWorkflowInterceptor.kt @@ -578,9 +578,9 @@ class TracingWorkflowInterceptor internal constructor( private val session: WorkflowSession ) : WorkflowAction { override fun Updater.apply() { - val oldState = nextState - val (newState, output) = delegate.applyTo(nextState) - nextState = newState + val oldState = state + val (newState, output) = delegate.applyTo(state) + state = newState output?.let { setOutput(it.value) } onWorkflowAction( workflowId = session.sessionId,