@@ -5,53 +5,56 @@ import com.squareup.workflow1.RuntimeConfigOptions
5
5
import com.squareup.workflow1.RuntimeConfigOptions.CONFLATE_STALE_RENDERINGS
6
6
import com.squareup.workflow1.RuntimeConfigOptions.PARTIAL_TREE_RENDERING
7
7
import com.squareup.workflow1.RuntimeConfigOptions.RENDER_ONLY_WHEN_STATE_CHANGES
8
+ import com.squareup.workflow1.RuntimeConfigOptions.STABLE_EVENT_HANDLERS
8
9
import com.squareup.workflow1.WorkflowExperimentalRuntime
9
10
10
11
public class JvmTestRuntimeConfigTools {
11
12
public companion object {
12
13
/* *
13
14
* Helper for Configuration for the workflow runtime in an application.
14
15
* 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
16
17
* into the application.
17
18
*
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.
21
24
*
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`):
27
26
*
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
30
30
* 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.
34
31
*
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.)
36
35
*
36
+ * - `stable` Enables stable event handlers (changes the default value of the `remember`
37
+ * parameter of `RenderContext.eventHandler` functions from `false` to `true`)
37
38
*/
38
39
@OptIn(WorkflowExperimentalRuntime ::class )
39
40
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 " , " " ).split( " - " )
42
+ // We used to have a no-op ` baseline` option, let's not choke on it.
43
+ .filterNot { it == " baseline " || it.isBlank() }
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
+ }
54
55
}
56
+
57
+ return config
55
58
}
56
59
}
57
60
}
0 commit comments