Skip to content

Commit

Permalink
Fix Build Issues with Kotlin 1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
steve-the-edwards committed Oct 23, 2023
1 parent 32b7833 commit 96b822a
Show file tree
Hide file tree
Showing 59 changed files with 2,750 additions and 2,574 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ kotlin_imports_layout = *,java.**,javax.**,kotlin.**,^
# test methods with descriptive names.
ktlint_ignore_back_ticked_identifier = true

ktlint_code_style = official
ktlint_code_style = ktlint_official
ktlint_function_signature_body_expression_wrapping = default
ktlint_function_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than = 3

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,192 +54,192 @@ class PerformancePoemsBrowserWorkflow(
PoemsBrowserWorkflow,
StatefulWorkflow<ConfigAndPoems, State, Unit, OverviewDetailScreen<*>>() {

sealed class State {
object Recurse : State()
sealed class State {
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 class ComplexCall(
val payload: Int
) : 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 class ComplexCall(
val payload: Int
) : State()

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

override fun initialState(
props: ConfigAndPoems,
snapshot: Snapshot?
): State {
return if (props.first.first > 0 &&
props.first.second == simulatedPerfConfig.recursionGraph.second
) {
Recurse
} else if (simulatedPerfConfig.useInitializingState) {
Initializing
} else {
NoSelection
override fun initialState(
props: ConfigAndPoems,
snapshot: Snapshot?
): State {
return if (props.first.first > 0 &&
props.first.second == simulatedPerfConfig.recursionGraph.second
) {
Recurse
} else if (simulatedPerfConfig.useInitializingState) {
Initializing
} else {
NoSelection
}
}
}

@OptIn(WorkflowUiExperimentalApi::class)
override fun render(
renderProps: ConfigAndPoems,
renderState: State,
context: RenderContext
): OverviewDetailScreen<*> {
when (renderState) {
is Recurse -> {
val recursiveChild = PerformancePoemsBrowserWorkflow(
simulatedPerfConfig,
poemWorkflow,
isLoading,
)
repeat(renderProps.first.second) { breadth ->
@OptIn(WorkflowUiExperimentalApi::class)
override fun render(
renderProps: ConfigAndPoems,
renderState: State,
context: RenderContext
): OverviewDetailScreen<*> {
when (renderState) {
is Recurse -> {
val recursiveChild = PerformancePoemsBrowserWorkflow(
simulatedPerfConfig,
poemWorkflow,
isLoading,
)
repeat(renderProps.first.second) { breadth ->
val nextProps = renderProps.copy(
first = renderProps.first.first - 1 to breadth
)
// When we repeat horizontally we ask the runtime to 'render' these Workflow nodes but
// we don't use their renderings in what is passed to the UI layer as this is just to
// fill out the Workflow tree to give the runtime more work to do. As such, we call
// renderChild here but we ignore the rendering returned and do no action on any Output.
// See SimulatedPerfConfig kdoc for more explanation.
context.renderChild(
child = recursiveChild,
props = nextProps,
key = "${nextProps.first},${nextProps.second}",
) {
noAction()
}
}
val nextProps = renderProps.copy(
first = renderProps.first.first - 1 to breadth
first = renderProps.first.first - 1 to renderProps.first.second
)
// When we repeat horizontally we ask the runtime to 'render' these Workflow nodes but
// we don't use their renderings in what is passed to the UI layer as this is just to
// fill out the Workflow tree to give the runtime more work to do. As such, we call
// renderChild here but we ignore the rendering returned and do no action on any Output.
// See SimulatedPerfConfig kdoc for more explanation.
context.renderChild(
return context.renderChild(
child = recursiveChild,
props = nextProps,
key = "${nextProps.first},${nextProps.second}",
) {
noAction()
}
}
val nextProps = renderProps.copy(
first = renderProps.first.first - 1 to renderProps.first.second
)
return context.renderChild(
child = recursiveChild,
props = nextProps,
key = "${nextProps.first},${nextProps.second}",
) {
action {
setOutput(it)
action {
setOutput(it)
}
}
}
}
// Again, then entire `Initializing` state is a smell, which is most obvious from the
// use of `Worker.from { Unit }`. A Worker doing no work and only shuttling the state
// along is usually the sign you have an extraneous state that can be collapsed!
// Don't try this at home.
is Initializing -> {
context.runningWorker(TraceableWorker.from("BrowserInitializing") { Unit }, "init") {
isLoading.value = true
action {
isLoading.value = false
state = NoSelection
// Again, then entire `Initializing` state is a smell, which is most obvious from the
// use of `Worker.from { Unit }`. A Worker doing no work and only shuttling the state
// along is usually the sign you have an extraneous state that can be collapsed!
// Don't try this at home.
is Initializing -> {
context.runningWorker(TraceableWorker.from("BrowserInitializing") { Unit }, "init") {
isLoading.value = true
action {
isLoading.value = false
state = NoSelection
}
}
return OverviewDetailScreen(overviewRendering = BackStackScreen(BlankScreen))
}
return OverviewDetailScreen(overviewRendering = BackStackScreen(BlankScreen))
}

is ComplexCall, is NoSelection, is Selected -> {
if (simulatedPerfConfig.simultaneousActions > 0) {
repeat(simulatedPerfConfig.simultaneousActions) { index ->
context.runningWorker(
worker = isLoading.asTraceableWorker("SimultaneousSubscribeBrowser-$index"),
key = "Browser-$index"
) {
noAction()
is ComplexCall, is NoSelection, is Selected -> {
if (simulatedPerfConfig.simultaneousActions > 0) {
repeat(simulatedPerfConfig.simultaneousActions) { index ->
context.runningWorker(
worker = isLoading.asTraceableWorker("SimultaneousSubscribeBrowser-$index"),
key = "Browser-$index"
) {
noAction()
}
}
}
}
val poemListProps = Props(
poems = renderProps.second,
eventHandlerTag = ActionHandlingTracingInterceptor::keyForTrace
)
val poemListRendering = context.renderChild(PoemListWorkflow, poemListProps) { selected ->
choosePoem(selected)
}
when (renderState) {
is NoSelection -> {
return OverviewDetailScreen(
overviewRendering = BackStackScreen(
poemListRendering.copy(selection = NO_POEM_SELECTED)
)
)
val poemListProps = Props(
poems = renderProps.second,
eventHandlerTag = ActionHandlingTracingInterceptor::keyForTrace
)
val poemListRendering = context.renderChild(PoemListWorkflow, poemListProps) { selected ->
choosePoem(selected)
}
when (renderState) {
is NoSelection -> {
return OverviewDetailScreen(
overviewRendering = BackStackScreen(
poemListRendering.copy(selection = NO_POEM_SELECTED)
)
)
}

is ComplexCall -> {
context.runningWorker(
TraceableWorker.from("ComplexCallBrowser(${renderState.payload})") {
isLoading.value = true
delay(simulatedPerfConfig.complexityDelay)
// No Output for Worker is necessary because the selected index
// is already in the state.
}
) {
action {
isLoading.value = false
(state as? ComplexCall)?.let { currentState ->
state = if (currentState.payload != NO_POEM_SELECTED) {
Selected(currentState.payload)
} else {
NoSelection
is ComplexCall -> {
context.runningWorker(
TraceableWorker.from("ComplexCallBrowser(${renderState.payload})") {
isLoading.value = true
delay(simulatedPerfConfig.complexityDelay)
// No Output for Worker is necessary because the selected index
// is already in the state.
}
) {
action {
isLoading.value = false
(state as? ComplexCall)?.let { currentState ->
state = if (currentState.payload != NO_POEM_SELECTED) {
Selected(currentState.payload)
} else {
NoSelection
}
}
}
}
var poems: OverviewDetailScreen<*> = OverviewDetailScreen(
overviewRendering = BackStackScreen(
poemListRendering.copy(selection = renderState.payload)
)
)
if (renderState.payload != NO_POEM_SELECTED) {
val poem = context.renderChild(
poemWorkflow,
renderProps.second[renderState.payload]
) { clearSelection }
poems += poem
}
return poems
}
var poems: OverviewDetailScreen<*> = OverviewDetailScreen(
overviewRendering = BackStackScreen(
poemListRendering.copy(selection = renderState.payload)

is Selected -> {
val poems = OverviewDetailScreen(
overviewRendering = BackStackScreen(
poemListRendering.copy(selection = renderState.poemIndex)
)
)
)
if (renderState.payload != NO_POEM_SELECTED) {
val poem = context.renderChild(
poemWorkflow,
renderProps.second[renderState.payload]
renderProps.second[renderState.poemIndex]
) { clearSelection }
poems += poem
return poems + poem
}
return poems
}

is Selected -> {
val poems = OverviewDetailScreen(
overviewRendering = BackStackScreen(
poemListRendering.copy(selection = renderState.poemIndex)
)
)
val poem = context.renderChild(
poemWorkflow,
renderProps.second[renderState.poemIndex]
) { clearSelection }
return poems + poem
}

else -> {
throw IllegalStateException("State can't change while rendering.")
else -> {
throw IllegalStateException("State can't change while rendering.")
}
}
}
}
}
}

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

private fun choosePoem(
index: Int
) = action {
state = if (simulatedPerfConfig.isComplex) {
ComplexCall(payload = index)
} else {
if (index != NO_POEM_SELECTED) {
Selected(index)
private fun choosePoem(
index: Int
) = action {
state = if (simulatedPerfConfig.isComplex) {
ComplexCall(payload = index)
} else {
NoSelection
if (index != NO_POEM_SELECTED) {
Selected(index)
} else {
NoSelection
}
}
}
}

private val clearSelection = choosePoem(NO_POEM_SELECTED)
}
private val clearSelection = choosePoem(NO_POEM_SELECTED)
}
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ subprojects {

// URL showing where the source code can be accessed through the web browser
remoteUrl.set(
@Suppress("ktlint:max-line-length")
@Suppress("ktlint:standard:max-line-length")
URL(
"https://github.com/square/workflow-kotlin/blob/main/$modulePath/src/${dokkaSourceSet.name}"
)
Expand Down
Loading

0 comments on commit 96b822a

Please sign in to comment.