Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

action {}, eventHandler {} with no debugging name is deprecated #1226

Merged
merged 1 commit into from
Nov 4, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class MaybeLoadingGatekeeperWorkflow<T : Any>(
context: RenderContext
): MayBeLoadingScreen {
context.runningWorker(isLoading.asTraceableWorker("GatekeeperLoading")) {
action {
action("GatekeeperLoading") {
state = it
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class PerformancePoemWorkflow(
},
"initializing"
) {
action {
action("initializing") {
isLoading.value = false
state = Selected(NO_SELECTED_STANZA)
}
Expand All @@ -148,7 +148,7 @@ class PerformancePoemWorkflow(
}
}.asTraceableWorker("EventRepetition")
) {
action {
action("currentStateIsLoading delay") {
(state as? ComplexCall)?.let { currentState ->
// Still repeating the complex call
state = ComplexCall(
Expand All @@ -167,7 +167,7 @@ class PerformancePoemWorkflow(
// is already in the state.
}
) {
action {
action("loaded") {
isLoading.value = false
(state as? ComplexCall)?.let { currentState ->
state = Selected(currentState.payload)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,17 @@ class PerformancePoemsBrowserWorkflow(
StatefulWorkflow<ConfigAndPoems, State, Unit, OverviewDetailScreen<*>>() {

sealed class State {
object Recurse : State()
data object Recurse : State()

// N.B. This state is a smell. We include it to be able to mimic smells
// we encounter in real life. Best practice would be to fold it
// into [NoSelection] at the very least.
object Initializing : State()
data object Initializing : State()
data class ComplexCall(
val payload: Int
) : State()

object NoSelection : State()
data object NoSelection : State()
data class Selected(val poemIndex: Int) : State()
}

Expand Down Expand Up @@ -122,7 +122,7 @@ class PerformancePoemsBrowserWorkflow(
props = nextProps,
key = "${nextProps.first},${nextProps.second}",
) {
action {
action("setOutput") {
setOutput(it)
}
}
Expand All @@ -134,7 +134,7 @@ class PerformancePoemsBrowserWorkflow(
is Initializing -> {
context.runningWorker(TraceableWorker.from("BrowserInitializing") { Unit }, "init") {
isLoading.value = true
action {
action("onInitialized") {
isLoading.value = false
state = NoSelection
}
Expand Down Expand Up @@ -178,7 +178,7 @@ class PerformancePoemsBrowserWorkflow(
// is already in the state.
}
) {
action {
action("onComplexCall") {
isLoading.value = false
(state as? ComplexCall)?.let { currentState ->
state = if (currentState.payload != NO_POEM_SELECTED) {
Expand Down Expand Up @@ -229,7 +229,7 @@ class PerformancePoemsBrowserWorkflow(

private fun choosePoem(
index: Int
) = action {
) = action("choosePoem") {
state = if (simulatedPerfConfig.isComplex) {
ComplexCall(payload = index)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ object HelloComposeWorkflow : StatefulWorkflow<Unit, State, Nothing, HelloCompos
}
}

private val helloAction = action {
private val helloAction = action("hello") {
state = state.theOtherState()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ object HelloWorkflow : StatefulWorkflow<Unit, State, Nothing, Rendering>() {
val onClick: () -> Unit
) : Screen

private val helloAction = action {
private val helloAction = action("hello") {
state = state.theOtherState()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,5 @@ internal class ComposeWorkflowImpl<PropsT, OutputT : Any>(
// Compiler bug doesn't let us call Snapshot.EMPTY.
override fun snapshotState(state: State<PropsT, OutputT>): Snapshot = Snapshot.of("")

private fun forwardOutput(output: OutputT) = action { setOutput(output) }
private fun forwardOutput(output: OutputT) = action("forwardOutput") { setOutput(output) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ object HelloWorkflow : StatefulWorkflow<Unit, State, Nothing, ComposeScreen>() {
}
}

private val helloAction = action {
private val helloAction = action("hello") {
state = state.theOtherState()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ object InlineRenderingWorkflow : StatefulWorkflow<Unit, Int, Nothing, Screen>()
context: RenderContext
) = ComposeScreen {
Box {
Button(onClick = context.eventHandler { state += 1 }) {
Button(onClick = context.eventHandler("increment") { state += 1 }) {
Text("Counter: ")
AnimatedCounter(renderState) { counterValue ->
Text(counterValue.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ object RecursiveWorkflow : StatefulWorkflow<Unit, State, Nothing, Screen>() {

override fun snapshotState(state: State): Snapshot? = null

private fun addChild() = action {
private fun addChild() = action("addChild") {
state = state.copy(children = state.children + 1)
}

private fun reset() = action {
private fun reset() = action("reset") {
state = State()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ object TextInputWorkflow : StatefulWorkflow<Unit, State, Nothing, Rendering>() {
val onSwapText: () -> Unit
) : Screen

private val swapText = action {
private val swapText = action("swapText") {
state = state.copy(showingTextA = !state.showingTextA)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ object AreYouSureWorkflow :

override fun snapshotState(state: State) = state.toSnapshot()

private val maybeQuit = action { state = Quitting }
private val confirmQuit = action { setOutput(Finished) }
private val cancelQuit = action { state = Running }
private val maybeQuit = action("maybeQuit") { state = Quitting }
private val confirmQuit = action("confirmQuit") { setOutput(Finished) }
private val cancelQuit = action("cancelQuit") { state = Running }
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object HelloBackButtonWorkflow : StatefulWorkflow<Unit, State, Nothing, HelloBac
): HelloBackButtonScreen {
return HelloBackButtonScreen(
message = "$renderState",
onClick = context.eventHandler {
onClick = context.eventHandler("onClick") {
state = when (state) {
Able -> Baker
Baker -> Charlie
Expand All @@ -42,7 +42,7 @@ object HelloBackButtonWorkflow : StatefulWorkflow<Unit, State, Nothing, HelloBac
onBackPressed = if (renderState == Able) {
null
} else {
context.eventHandler {
context.eventHandler("onBackPressed") {
state = when (state) {
Able -> throw IllegalStateException()
Baker -> Able
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ object PoemListWorkflow : StatelessWorkflow<Props, Int, PoemListScreen>() {
return PoemListScreen(
poems = renderProps.poems,
onPoemSelected = context.eventHandler(
name = { renderProps.eventHandlerTag("E-PoemList-PoemSelected") }
name = renderProps.eventHandlerTag("E-PoemList-PoemSelected")
) { index -> setOutput(index) }
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,13 @@ object StanzaListWorkflow : StatelessWorkflow<Props, SelectedStanza, StanzaListS
subtitle = poem.poet.fullName,
firstLines = poem.initialStanzas,
onStanzaSelected = context.eventHandler(
name = { renderProps.eventHandlerTag("E-StanzaList-StanzaSelected") }
name = renderProps.eventHandlerTag("E-StanzaList-StanzaSelected")
) { index ->
setOutput(
index
)
},
onExit = context.eventHandler(
name = { renderProps.eventHandlerTag("E-StanzaList-Exit") }
) {
onExit = context.eventHandler(name = renderProps.eventHandlerTag("E-StanzaList-Exit")) {
setOutput(
NO_SELECTED_STANZA
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ object StanzaWorkflow : StatelessWorkflow<Props, Output, StanzaScreen>() {
0 -> null
else -> {
context.eventHandler(
name = { renderProps.eventHandlerTag("E-StanzaWorkflow-${ShowPreviousStanza.name}") }
name = renderProps.eventHandlerTag("E-StanzaWorkflow-${ShowPreviousStanza.name}")
) {
setOutput(
ShowPreviousStanza
Expand All @@ -43,7 +43,7 @@ object StanzaWorkflow : StatelessWorkflow<Props, Output, StanzaScreen>() {
poem.stanzas.size - 1 -> null
else -> {
context.eventHandler(
name = { renderProps.eventHandlerTag("E-StanzaWorkflow-${ShowNextStanza.name}") }
name = renderProps.eventHandlerTag("E-StanzaWorkflow-${ShowNextStanza.name}")
) {
setOutput(
ShowNextStanza
Expand All @@ -54,7 +54,7 @@ object StanzaWorkflow : StatelessWorkflow<Props, Output, StanzaScreen>() {

return StanzaScreen(
onGoUp = context.eventHandler(
name = { renderProps.eventHandlerTag("E-StanzaWorkflow-${CloseStanzas.name}") }
name = renderProps.eventHandlerTag("E-StanzaWorkflow-${CloseStanzas.name}")
) {
setOutput(
CloseStanzas
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ class DungeonAppWorkflow(

override fun snapshotState(state: State): Snapshot? = null

private fun displayBoards(boards: Map<String, Board>) = action {
private fun displayBoards(boards: Map<String, Board>) = action("displayBoards") {
state = ChoosingBoard(boards.toList())
}

private fun selectBoard(index: Int) = action {
private fun selectBoard(index: Int) = action("selectBoard") {
// No-op if we're not in the ChoosingBoard state.
val boards = (state as? ChoosingBoard)?.boards ?: return@action
state = PlayingGame(boards[index].first)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class ShakeableTimeMachineWorkflow<in P, O : Any, out R : Screen>(
)
}

private val onShake = action {
private val onShake = action("onShake") {
state = PlayingBack(Duration.INFINITE)
}

Expand All @@ -122,5 +122,5 @@ class ShakeableTimeMachineWorkflow<in P, O : Any, out R : Screen>(
}
}

private fun forwardOutput(output: O) = action { setOutput(output) }
private fun forwardOutput(output: O) = action("forwardOutput") { setOutput(output) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,5 @@ class TimeMachineWorkflow<P, O : Any, out R>(
return context.renderChild(recordingWorkflow, recorderProps)
}

private fun forwardOutput(output: O) = action { setOutput(output) }
private fun forwardOutput(output: O) = action("forwardOutput") { setOutput(output) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class TimeMachineWorkflowTest {
val delegateWorkflow = Workflow.stateful<String, Nothing, DelegateRendering>(
initialState = "initial",
render = { renderState ->
DelegateRendering(renderState, setState = eventHandler { s -> state = s })
DelegateRendering(renderState, setState = eventHandler("") { s -> state = s })
rjrjr marked this conversation as resolved.
Show resolved Hide resolved
}
)
val clock = TestTimeSource()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class BlinkingCursorWorkflow(

override fun snapshotState(state: Boolean): Snapshot? = null

private fun setCursorShowing(showing: Boolean) = action {
private fun setCursorShowing(showing: Boolean) = action("setCursorShowing") {
state = showing
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class HelloTerminalWorkflow : TerminalWorkflow,

override fun snapshotState(state: State): Snapshot? = null

private fun onKeystroke(key: KeyStroke): HelloTerminalAction = action {
private fun onKeystroke(key: KeyStroke): HelloTerminalAction = action("onKeystroke") {
when {
key.character == 'Q' -> setOutput(0)
key.keyType == Backspace -> state = state.backspace()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class EditTextWorkflow : StatefulWorkflow<EditTextProps, EditTextState, String,

private fun onKeystroke(
key: KeyStroke
) = action {
) = action("onKeystroke") {
when (key.keyType) {
Character -> {
val newText = props.text.insertCharAt(state.cursorPosition, key.character!!)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class TodoWorkflow : TerminalWorkflow,

override fun snapshotState(state: TodoList): Snapshot? = null

private fun onKeystroke(key: KeyStroke) = action {
private fun onKeystroke(key: KeyStroke) = action("onKeystroke") {
when (key.keyType) {
ArrowUp -> state = state.moveFocusUp()
ArrowDown -> state = state.moveFocusDown()
Expand All @@ -90,14 +90,14 @@ class TodoWorkflow : TerminalWorkflow,
}
}

private fun updateTitle(newTitle: String): TodoAction = action {
private fun updateTitle(newTitle: String): TodoAction = action("updateTitle") {
state = state.copy(title = newTitle)
}

private fun setLabel(
index: Int,
text: String
): TodoAction = action {
): TodoAction = action("setLabel") {
state = state.copy(
items = state.items.mapIndexed { i, item ->
if (index == i) item.copy(label = text) else item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ object HelloWorkflow : StatefulWorkflow<Unit, State, Nothing, HelloRendering>()

override fun snapshotState(state: State): Snapshot = Snapshot.of(if (state == Hello) 1 else 0)

private val helloAction = action {
private val helloAction = action("hello") {
state = when (state) {
Hello -> Goodbye
Goodbye -> Hello
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ object HelloWorkflow : StatefulWorkflow<Unit, State, Nothing, HelloRendering>()

override fun snapshotState(state: State): Snapshot = Snapshot.of(if (state == Hello) 1 else 0)

private val helloAction = action {
private val helloAction = action("hello") {
state = when (state) {
Hello -> Goodbye
Goodbye -> Hello
Expand Down
Loading
Loading