Skip to content

Commit 8075035

Browse files
committed
Adds STABLE_EVENT_HANDLERS to runtime config tools
Overhauls the config calls. Doesn't actually use the new config option yet, incremental change due to CI problems.
1 parent 4d8f5bc commit 8075035

File tree

2 files changed

+61
-56
lines changed

2 files changed

+61
-56
lines changed

workflow-config/config-android/src/main/java/com/squareup/workflow1/config/AndroidRuntimeConfigTools.kt

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,52 +5,54 @@ import com.squareup.workflow1.RuntimeConfigOptions
55
import com.squareup.workflow1.RuntimeConfigOptions.CONFLATE_STALE_RENDERINGS
66
import com.squareup.workflow1.RuntimeConfigOptions.PARTIAL_TREE_RENDERING
77
import com.squareup.workflow1.RuntimeConfigOptions.RENDER_ONLY_WHEN_STATE_CHANGES
8+
import com.squareup.workflow1.RuntimeConfigOptions.STABLE_EVENT_HANDLERS
89
import com.squareup.workflow1.WorkflowExperimentalRuntime
910

1011
public class AndroidRuntimeConfigTools {
11-
1212
public companion object {
1313
/**
1414
* Helper for Configuration for the workflow runtime in an application.
1515
* This allows one to specify a project property from the gradle build to choose a runtime.
16-
* e.g. add "-Pworkflow.runtime=conflate" in your gradle build to build the conflate runtime
16+
* e.g. add `-Pworkflow.runtime=conflate` in your gradle build to build the conflate runtime
1717
* into the application.
1818
*
1919
* Note that this must be specified in the application built for any ui/integration tests. Call
20-
* this function, and then pass that to the call to [renderWorkflowIn] as the [RuntimeConfig].
20+
* this function and pass the result to [renderWorkflowIn][com.squareup.workflow1.renderWorkflowIn]
21+
* as the [RuntimeConfig] parameter.
22+
*
23+
* Current options (can be combined with `-` characters, e.g. `conflate-partial`):
2124
*
22-
* Current options are:
23-
* "conflate" : Process all queued actions before passing rendering
24-
* to the UI layer.
25-
* "baseline" : Original Workflow Runtime. Note that this doesn't need to
26-
* be specified as it is the current default and is assumed by this utility.
25+
* - `conflate` Process all queued actions before passing rendering to the UI layer.
2726
*
28-
* Then, these can be combined (via '-') with:
29-
* "stateChange" : Only re-render when the state of some WorkflowNode has been changed by an
27+
* - `stateChange` Only re-render when the state of some WorkflowNode has been changed by an
3028
* action cascade.
31-
* "partial" : Which includes "stateChange" as well as partial tree rendering, which only
32-
* re-renders each Workflow node if: 1) its state changed; or 2) one of its descendant's state
33-
* changed.
3429
*
35-
* E.g., "baseline-stateChange" to turn on the stateChange option with the baseline runtime.
30+
* - `partial` Partial tree rendering, which only re-renders each Workflow node if: 1) its
31+
* state changed; or 2) one of its descendant's state changed. (This option requires
32+
* `stateChange`, and enables it as well.)
3633
*
34+
* - `stable` Enables stable event handlers (changes the default value of the `remember`
35+
* parameter of `RenderContext.eventHandler` functions from `false` to `true`)
3736
*/
3837
@WorkflowExperimentalRuntime
3938
public fun getAppWorkflowRuntimeConfig(): RuntimeConfig {
40-
return when (BuildConfig.WORKFLOW_RUNTIME) {
41-
"conflate" -> setOf(CONFLATE_STALE_RENDERINGS)
42-
"conflate-stateChange" -> setOf(CONFLATE_STALE_RENDERINGS, RENDER_ONLY_WHEN_STATE_CHANGES)
43-
"baseline-stateChange" -> setOf(RENDER_ONLY_WHEN_STATE_CHANGES)
44-
"conflate-partial" -> setOf(
45-
CONFLATE_STALE_RENDERINGS,
46-
RENDER_ONLY_WHEN_STATE_CHANGES,
47-
PARTIAL_TREE_RENDERING
48-
)
49-
"baseline-partial" -> setOf(RENDER_ONLY_WHEN_STATE_CHANGES, PARTIAL_TREE_RENDERING)
50-
"", "baseline" -> RuntimeConfigOptions.RENDER_PER_ACTION
51-
else ->
52-
throw IllegalArgumentException("Unrecognized config \"${BuildConfig.WORKFLOW_RUNTIME}\"")
39+
val selection = BuildConfig.WORKFLOW_RUNTIME.split("-")
40+
// We used to have a no-op `baseline` option, let's not choke on it.
41+
.filterNot { it == "baseline" }
42+
.toSet()
43+
44+
val config = mutableSetOf<RuntimeConfigOptions>()
45+
selection.forEach {
46+
when (it) {
47+
"conflate" -> config.add(CONFLATE_STALE_RENDERINGS)
48+
"stateChange" -> config.add(RENDER_ONLY_WHEN_STATE_CHANGES)
49+
"partial" -> config.addAll(setOf(RENDER_ONLY_WHEN_STATE_CHANGES, PARTIAL_TREE_RENDERING))
50+
"stable" -> config.add(STABLE_EVENT_HANDLERS)
51+
else -> throw IllegalArgumentException("Unrecognized runtime config option \"$it\"")
52+
}
5353
}
54+
55+
return config
5456
}
5557
}
5658
}

workflow-config/config-jvm/src/main/java/com/squareup/workflow1/config/JvmTestRuntimeConfigTools.kt

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,53 +5,56 @@ import com.squareup.workflow1.RuntimeConfigOptions
55
import com.squareup.workflow1.RuntimeConfigOptions.CONFLATE_STALE_RENDERINGS
66
import com.squareup.workflow1.RuntimeConfigOptions.PARTIAL_TREE_RENDERING
77
import com.squareup.workflow1.RuntimeConfigOptions.RENDER_ONLY_WHEN_STATE_CHANGES
8+
import com.squareup.workflow1.RuntimeConfigOptions.STABLE_EVENT_HANDLERS
89
import com.squareup.workflow1.WorkflowExperimentalRuntime
910

1011
public class JvmTestRuntimeConfigTools {
1112
public companion object {
1213
/**
1314
* Helper for Configuration for the workflow runtime in an application.
1415
* This allows one to specify a project property from the gradle build to choose a runtime.
15-
* e.g. add "-Pworkflow.runtime=conflate" in your gradle build to build the conflate runtime
16+
* e.g. add `-Pworkflow.runtime=conflate` in your gradle build to build the conflate runtime
1617
* into the application.
1718
*
18-
* The [WorkflowTestRuntime] already calls this utility, but if starting your own runtime, then
19-
* call this function and pass the result to the call to [renderWorkflowIn] as the
20-
* [RuntimeConfig].
19+
* The [WorkflowTestRuntime][com.squareup.workflow1.testing.WorkflowTestRuntime]
20+
* and [RenderTester][com.squareup.workflow1.testing.RenderTester] runtimes
21+
* already call this utility. To honor this property from your own runtime call this
22+
* function and pass the result to the call to
23+
* [renderWorkflowIn][com.squareup.workflow1.renderWorkflowIn] as the [RuntimeConfig] parameter.
2124
*
22-
* Current options are:
23-
* "conflate" : Process all queued actions before passing rendering
24-
* to the UI layer.
25-
* "baseline" : Original Workflow Runtime. Note that this doesn't need to
26-
* be specified as it is the current default and is assumed by this utility.
25+
* Current options (can be combined with `-` characters, e.g. `conflate-partial`):
2726
*
28-
* Then, these can be combined (via '-') with:
29-
* "stateChange" : Only re-render when the state of some WorkflowNode has been changed by an
27+
* - `conflate` Process all queued actions before passing rendering to the UI layer.
28+
*
29+
* - `stateChange` Only re-render when the state of some WorkflowNode has been changed by an
3030
* action cascade.
31-
* "partial" : Which includes "stateChange" as well as partial tree rendering, which only
32-
* re-renders each Workflow node if: 1) its state changed; or 2) one of its descendant's state
33-
* changed.
3431
*
35-
* E.g., "baseline-stateChange" to turn on the stateChange option with the baseline runtime.
32+
* - `partial` Partial tree rendering, which only re-renders each Workflow node if: 1) its
33+
* state changed; or 2) one of its descendant's state changed. (This option requires
34+
* `stateChange`, and enables it as well.)
3635
*
36+
* - `stable` Enables stable event handlers (changes the default value of the `remember`
37+
* parameter of `RenderContext.eventHandler` functions from `false` to `true`)
3738
*/
3839
@OptIn(WorkflowExperimentalRuntime::class)
3940
public fun getTestRuntimeConfig(): RuntimeConfig {
40-
return when
41-
(val runtimeConfig = System.getProperty("workflow.runtime", "baseline")) {
42-
"conflate" -> setOf(CONFLATE_STALE_RENDERINGS)
43-
"conflate-stateChange" -> setOf(CONFLATE_STALE_RENDERINGS, RENDER_ONLY_WHEN_STATE_CHANGES)
44-
"baseline-stateChange" -> setOf(RENDER_ONLY_WHEN_STATE_CHANGES)
45-
"conflate-partial" -> setOf(
46-
CONFLATE_STALE_RENDERINGS,
47-
RENDER_ONLY_WHEN_STATE_CHANGES,
48-
PARTIAL_TREE_RENDERING
49-
)
50-
"baseline-partial" -> setOf(RENDER_ONLY_WHEN_STATE_CHANGES, PARTIAL_TREE_RENDERING)
51-
"", "baseline" -> RuntimeConfigOptions.RENDER_PER_ACTION
52-
else ->
53-
throw IllegalArgumentException("Unrecognized config \"$runtimeConfig\"")
41+
val selection = System.getProperty("workflow.runtime", "baseline").split("-")
42+
// We used to have a no-op `baseline` option, let's not choke on it.
43+
.filterNot { it == "baseline" }
44+
.toSet()
45+
46+
val config = mutableSetOf<RuntimeConfigOptions>()
47+
selection.forEach {
48+
when (it) {
49+
"conflate" -> config.add(CONFLATE_STALE_RENDERINGS)
50+
"stateChange" -> config.add(RENDER_ONLY_WHEN_STATE_CHANGES)
51+
"partial" -> config.addAll(setOf(RENDER_ONLY_WHEN_STATE_CHANGES, PARTIAL_TREE_RENDERING))
52+
"stable" -> config.add(STABLE_EVENT_HANDLERS)
53+
else -> throw IllegalArgumentException("Unrecognized runtime config option \"$it\"")
54+
}
5455
}
56+
57+
return config
5558
}
5659
}
5760
}

0 commit comments

Comments
 (0)