@@ -24,8 +24,39 @@ protocol ApplyContextType<WorkflowType> {
2424}
2525
2626/// Runtime context passed as a parameter to `WorkflowAction`'s `apply()` method
27- /// that provides an integration point with the runtime that can be used to read property values
28- /// off of the current `Workflow` instance.
27+ /// that provides an integration point with the runtime that can be used to read values from
28+ /// the current `Workflow` instance.
29+ ///
30+ /// Read-only access to `Workflow` values is exposed via the `subscript[workflowValue:]` API,
31+ /// which accepts a read-only `KeyPath` to a `Workflow`'s value.
32+ ///
33+ /// Usage example:
34+ ///
35+ /// ```swift
36+ /// struct MyWorkflow: Workflow {
37+ /// let shouldSuppressOutput: Bool
38+ ///
39+ /// // ... implementation ...
40+ /// }
41+ ///
42+ /// enum MyAction: WorkflowAction {
43+ /// typealias WorkflowType = MyWorkflow
44+ ///
45+ /// case one
46+ /// case two
47+ ///
48+ /// func apply(toState state: inout WorkflowType.State, context: ApplyContext<WorkflowType>) -> WorkflowType.Output? {
49+ /// // Make conditional choices based on the `Workflow`'s instance values
50+ /// let shouldSuppressOutput = context[workflowValue: \.shouldSuppressOutput]
51+ /// if shouldSuppressOutput { return nil }
52+ ///
53+ /// // ... implementation ...
54+ /// }
55+ /// }
56+ /// ```
57+ ///
58+ /// > Warning: The instance of this type passed to the `apply()` method should not escape from that method.
59+ /// Attempting to access the instance after the `apply()` method has returned is a client error and will crash.
2960public struct ApplyContext < WorkflowType: Workflow > {
3061 let wrappedContext : any ApplyContextType < WorkflowType >
3162
0 commit comments