Skip to content

Commit f4597ac

Browse files
authored
Document how WorkflowAction can delegate
It's an obscure use case, but it comes up every now and then
1 parent fc03c13 commit f4597ac

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

workflow-core/src/commonMain/kotlin/com/squareup/workflow1/WorkflowAction.kt

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,28 @@ import kotlin.jvm.JvmOverloads
1010

1111
/**
1212
* An atomic operation that updates the state of a [Workflow], and also optionally emits an output.
13+
*
14+
* A [WorkflowAction]'s [apply] method is executed in the context of an [Updater][WorkflowAction.Updater],
15+
* which provides access to the current [props][WorkflowAction.Updater.props] and
16+
* [state][WorkflowAction.Updater.props]. The latter can be updated with a new [StateT] instance
17+
* that will become the current one after the [apply] function finishes.
18+
*
19+
* It is possible for one [WorkflowAction] to delegate to another, although the API is a bit opaque:
20+
*
21+
* val actionA = action {
22+
* }
23+
*
24+
* val actionB = action {
25+
* val (newState, outputApplied) = actionA.applyTo(props, state)
26+
* state = newState
27+
* outputApplied.output?.value?.let { setOutput(it) }
28+
* }
1329
*/
1430
public abstract class WorkflowAction<in PropsT, StateT, out OutputT> {
1531

1632
/**
17-
* The context for calls to [WorkflowAction.apply]. Allows the action to set the
18-
* [state], and to emit the [setOutput].
33+
* The context for calls to [WorkflowAction.apply]. Allows the action to read and change the
34+
* [state], and to emit an [output][setOutput] value.
1935
*
2036
* @param state the state that the workflow should move to. Default is the current state.
2137
*/

0 commit comments

Comments
 (0)