diff --git a/.github/workflows/kotlin.yml b/.github/workflows/kotlin.yml index bb54529b77..138a53ac92 100644 --- a/.github/workflows/kotlin.yml +++ b/.github/workflows/kotlin.yml @@ -212,7 +212,7 @@ jobs : - name : Check with Gradle uses : ./.github/actions/gradle-task with : - task : jvmTest --continue -Pworkflow.runtime=baseline-stateChange + task : jvmTest --continue -Pworkflow.runtime=stateChange restore-cache-key : main-build-artifacts # Report as GitHub Pull Request Check. @@ -222,6 +222,27 @@ jobs : with : report_paths : '**/build/test-results/test/TEST-*.xml' + jvm-stable-handlers-test: + name: Stable Event Handlers Only Runtime JVM Tests + runs-on: ubuntu-latest + timeout-minutes: 20 + steps: + - name: Checkout + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + + - name: Check with Gradle + uses: ./.github/actions/gradle-task + with: + task: jvmTest --continue -Pworkflow.runtime=stable + restore-cache-key: main-build-artifacts + + # Report as GitHub Pull Request Check. + - name: Publish Test Report + uses: mikepenz/action-junit-report@5f47764eec0e1c1f19f40c8e60a5ba47e47015c5 # v4 + if: always() # always run even if the previous step fails + with: + report_paths: '**/build/test-results/test/TEST-*.xml' + jvm-partial-runtime-test: name: Partial Tree Rendering Only Runtime JVM Tests runs-on: ubuntu-latest @@ -233,7 +254,7 @@ jobs : - name: Check with Gradle uses: ./.github/actions/gradle-task with: - task: jvmTest --continue -Pworkflow.runtime=baseline-partial + task: jvmTest --continue -Pworkflow.runtime=partial restore-cache-key: main-build-artifacts # Report as GitHub Pull Request Check. @@ -391,7 +412,7 @@ jobs : ### shardNum: [ 1, 2, 3 ] ### - runtime : [ conflate, baseline-stateChange, conflate-stateChange, baseline-partial, conflate-partial ] + runtime : [ conflate, stateChange, conflate-stateChange, partial, conflate-partial, stable ] steps : - name: Checkout uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 @@ -421,6 +442,7 @@ jobs : - js-tests - jvm-conflate-runtime-test - jvm-stateChange-runtime-test + - jvm-stable-handlers-test - jvm-partial-runtime-test - jvm-conflate-stateChange-runtime-test - jvm-conflate-partial-runtime-test diff --git a/workflow-config/config-android/src/main/java/com/squareup/workflow1/config/AndroidRuntimeConfigTools.kt b/workflow-config/config-android/src/main/java/com/squareup/workflow1/config/AndroidRuntimeConfigTools.kt index 7df4791984..05c3f32ce3 100644 --- a/workflow-config/config-android/src/main/java/com/squareup/workflow1/config/AndroidRuntimeConfigTools.kt +++ b/workflow-config/config-android/src/main/java/com/squareup/workflow1/config/AndroidRuntimeConfigTools.kt @@ -5,52 +5,54 @@ import com.squareup.workflow1.RuntimeConfigOptions import com.squareup.workflow1.RuntimeConfigOptions.CONFLATE_STALE_RENDERINGS import com.squareup.workflow1.RuntimeConfigOptions.PARTIAL_TREE_RENDERING import com.squareup.workflow1.RuntimeConfigOptions.RENDER_ONLY_WHEN_STATE_CHANGES +import com.squareup.workflow1.RuntimeConfigOptions.STABLE_EVENT_HANDLERS import com.squareup.workflow1.WorkflowExperimentalRuntime public class AndroidRuntimeConfigTools { - public companion object { /** * Helper for Configuration for the workflow runtime in an application. * This allows one to specify a project property from the gradle build to choose a runtime. - * e.g. add "-Pworkflow.runtime=conflate" in your gradle build to build the conflate runtime + * e.g. add `-Pworkflow.runtime=conflate` in your gradle build to build the conflate runtime * into the application. * * Note that this must be specified in the application built for any ui/integration tests. Call - * this function, and then pass that to the call to [renderWorkflowIn] as the [RuntimeConfig]. + * this function and pass the result to [renderWorkflowIn][com.squareup.workflow1.renderWorkflowIn] + * as the [RuntimeConfig] parameter. + * + * Current options (can be combined with `-` characters, e.g. `conflate-partial`): * - * Current options are: - * "conflate" : Process all queued actions before passing rendering - * to the UI layer. - * "baseline" : Original Workflow Runtime. Note that this doesn't need to - * be specified as it is the current default and is assumed by this utility. + * - `conflate` Process all queued actions before passing rendering to the UI layer. * - * Then, these can be combined (via '-') with: - * "stateChange" : Only re-render when the state of some WorkflowNode has been changed by an + * - `stateChange` Only re-render when the state of some WorkflowNode has been changed by an * action cascade. - * "partial" : Which includes "stateChange" as well as partial tree rendering, which only - * re-renders each Workflow node if: 1) its state changed; or 2) one of its descendant's state - * changed. * - * E.g., "baseline-stateChange" to turn on the stateChange option with the baseline runtime. + * - `partial` Partial tree rendering, which only re-renders each Workflow node if: 1) its + * state changed; or 2) one of its descendant's state changed. (This option requires + * `stateChange`, and enables it as well.) * + * - `stable` Enables stable event handlers (changes the default value of the `remember` + * parameter of `RenderContext.eventHandler` functions from `false` to `true`) */ @WorkflowExperimentalRuntime public fun getAppWorkflowRuntimeConfig(): RuntimeConfig { - return when (BuildConfig.WORKFLOW_RUNTIME) { - "conflate" -> setOf(CONFLATE_STALE_RENDERINGS) - "conflate-stateChange" -> setOf(CONFLATE_STALE_RENDERINGS, RENDER_ONLY_WHEN_STATE_CHANGES) - "baseline-stateChange" -> setOf(RENDER_ONLY_WHEN_STATE_CHANGES) - "conflate-partial" -> setOf( - CONFLATE_STALE_RENDERINGS, - RENDER_ONLY_WHEN_STATE_CHANGES, - PARTIAL_TREE_RENDERING - ) - "baseline-partial" -> setOf(RENDER_ONLY_WHEN_STATE_CHANGES, PARTIAL_TREE_RENDERING) - "", "baseline" -> RuntimeConfigOptions.RENDER_PER_ACTION - else -> - throw IllegalArgumentException("Unrecognized config \"${BuildConfig.WORKFLOW_RUNTIME}\"") + val selection = BuildConfig.WORKFLOW_RUNTIME.split("-") + // We used to have a no-op `baseline` option, let's not choke on it. + .filterNot { it == "baseline" || it.isBlank() } + .toSet() + + val config = mutableSetOf() + selection.forEach { + when (it) { + "conflate" -> config.add(CONFLATE_STALE_RENDERINGS) + "stateChange" -> config.add(RENDER_ONLY_WHEN_STATE_CHANGES) + "partial" -> config.addAll(setOf(RENDER_ONLY_WHEN_STATE_CHANGES, PARTIAL_TREE_RENDERING)) + "stable" -> config.add(STABLE_EVENT_HANDLERS) + else -> throw IllegalArgumentException("Unrecognized runtime config option \"$it\"") + } } + + return config } } } diff --git a/workflow-config/config-jvm/src/main/java/com/squareup/workflow1/config/JvmTestRuntimeConfigTools.kt b/workflow-config/config-jvm/src/main/java/com/squareup/workflow1/config/JvmTestRuntimeConfigTools.kt index 8d3358d352..da64d2fc3b 100644 --- a/workflow-config/config-jvm/src/main/java/com/squareup/workflow1/config/JvmTestRuntimeConfigTools.kt +++ b/workflow-config/config-jvm/src/main/java/com/squareup/workflow1/config/JvmTestRuntimeConfigTools.kt @@ -5,6 +5,7 @@ import com.squareup.workflow1.RuntimeConfigOptions import com.squareup.workflow1.RuntimeConfigOptions.CONFLATE_STALE_RENDERINGS import com.squareup.workflow1.RuntimeConfigOptions.PARTIAL_TREE_RENDERING import com.squareup.workflow1.RuntimeConfigOptions.RENDER_ONLY_WHEN_STATE_CHANGES +import com.squareup.workflow1.RuntimeConfigOptions.STABLE_EVENT_HANDLERS import com.squareup.workflow1.WorkflowExperimentalRuntime public class JvmTestRuntimeConfigTools { @@ -12,46 +13,48 @@ public class JvmTestRuntimeConfigTools { /** * Helper for Configuration for the workflow runtime in an application. * This allows one to specify a project property from the gradle build to choose a runtime. - * e.g. add "-Pworkflow.runtime=conflate" in your gradle build to build the conflate runtime + * e.g. add `-Pworkflow.runtime=conflate` in your gradle build to build the conflate runtime * into the application. * - * The [WorkflowTestRuntime] already calls this utility, but if starting your own runtime, then - * call this function and pass the result to the call to [renderWorkflowIn] as the - * [RuntimeConfig]. + * The [WorkflowTestRuntime][com.squareup.workflow1.testing.WorkflowTestRuntime] + * and [RenderTester][com.squareup.workflow1.testing.RenderTester] runtimes + * already call this utility. To honor this property from your own runtime call this + * function and pass the result to the call to + * [renderWorkflowIn][com.squareup.workflow1.renderWorkflowIn] as the [RuntimeConfig] parameter. * - * Current options are: - * "conflate" : Process all queued actions before passing rendering - * to the UI layer. - * "baseline" : Original Workflow Runtime. Note that this doesn't need to - * be specified as it is the current default and is assumed by this utility. + * Current options (can be combined with `-` characters, e.g. `conflate-partial`): * - * Then, these can be combined (via '-') with: - * "stateChange" : Only re-render when the state of some WorkflowNode has been changed by an + * - `conflate` Process all queued actions before passing rendering to the UI layer. + * + * - `stateChange` Only re-render when the state of some WorkflowNode has been changed by an * action cascade. - * "partial" : Which includes "stateChange" as well as partial tree rendering, which only - * re-renders each Workflow node if: 1) its state changed; or 2) one of its descendant's state - * changed. * - * E.g., "baseline-stateChange" to turn on the stateChange option with the baseline runtime. + * - `partial` Partial tree rendering, which only re-renders each Workflow node if: 1) its + * state changed; or 2) one of its descendant's state changed. (This option requires + * `stateChange`, and enables it as well.) * + * - `stable` Enables stable event handlers (changes the default value of the `remember` + * parameter of `RenderContext.eventHandler` functions from `false` to `true`) */ @OptIn(WorkflowExperimentalRuntime::class) public fun getTestRuntimeConfig(): RuntimeConfig { - return when - (val runtimeConfig = System.getProperty("workflow.runtime", "baseline")) { - "conflate" -> setOf(CONFLATE_STALE_RENDERINGS) - "conflate-stateChange" -> setOf(CONFLATE_STALE_RENDERINGS, RENDER_ONLY_WHEN_STATE_CHANGES) - "baseline-stateChange" -> setOf(RENDER_ONLY_WHEN_STATE_CHANGES) - "conflate-partial" -> setOf( - CONFLATE_STALE_RENDERINGS, - RENDER_ONLY_WHEN_STATE_CHANGES, - PARTIAL_TREE_RENDERING - ) - "baseline-partial" -> setOf(RENDER_ONLY_WHEN_STATE_CHANGES, PARTIAL_TREE_RENDERING) - "", "baseline" -> RuntimeConfigOptions.RENDER_PER_ACTION - else -> - throw IllegalArgumentException("Unrecognized config \"$runtimeConfig\"") + val selection = System.getProperty("workflow.runtime", "").split("-") + // We used to have a no-op `baseline` option, let's not choke on it. + .filterNot { it == "baseline" || it.isBlank() } + .toSet() + + val config = mutableSetOf() + selection.forEach { + when (it) { + "conflate" -> config.add(CONFLATE_STALE_RENDERINGS) + "stateChange" -> config.add(RENDER_ONLY_WHEN_STATE_CHANGES) + "partial" -> config.addAll(setOf(RENDER_ONLY_WHEN_STATE_CHANGES, PARTIAL_TREE_RENDERING)) + "stable" -> config.add(STABLE_EVENT_HANDLERS) + else -> throw IllegalArgumentException("Unrecognized runtime config option \"$it\"") + } } + + return config } } }