@@ -5,53 +5,56 @@ import com.squareup.workflow1.RuntimeConfigOptions
55import com.squareup.workflow1.RuntimeConfigOptions.CONFLATE_STALE_RENDERINGS
66import com.squareup.workflow1.RuntimeConfigOptions.PARTIAL_TREE_RENDERING
77import com.squareup.workflow1.RuntimeConfigOptions.RENDER_ONLY_WHEN_STATE_CHANGES
8+ import com.squareup.workflow1.RuntimeConfigOptions.STABLE_EVENT_HANDLERS
89import com.squareup.workflow1.WorkflowExperimentalRuntime
910
1011public 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