Skip to content

Commit 9063748

Browse files
committed
[docs]: update some docs per PR feedback
1 parent 33b6695 commit 9063748

File tree

5 files changed

+40
-5
lines changed

5 files changed

+40
-5
lines changed

Workflow/Sources/ApplyContext.swift

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
2960
public struct ApplyContext<WorkflowType: Workflow> {
3061
let wrappedContext: any ApplyContextType<WorkflowType>
3162

Workflow/Sources/WorkflowAction.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ public protocol WorkflowAction<WorkflowType> {
2424
///
2525
/// - Parameter state: The current state of the workflow. The state is passed as an `inout` param, allowing actions
2626
/// to modify state during application.
27+
/// - Parameter context: A context object provided by the runtime that enables reading values of the underlying `Workflow` instance.
2728
///
2829
/// - Returns: An optional output event for the workflow. If an output event is returned, it will be passed up
2930
/// the workflow hierarchy to this workflow's parent.
31+
/// > Warning: The `context` parameter should not escape from implementations of this requirement.
32+
/// Attempting to access the instance after `apply()` has returned is a client error and will crash.
3033
func apply(
3134
toState state: inout WorkflowType.State,
3235
context: ApplyContext<WorkflowType>

Workflow/Sources/WorkflowNode.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ extension WorkflowNode {
219219

220220
/// Apply the action to the current state
221221
do {
222-
// TODO: can we avoid instantiating a class here somehow?
222+
// FIXME: can we avoid instantiating a class here somehow?
223223
let context = ConcreteApplyContext(storage: workflow)
224224
defer { context.invalidate() }
225225

WorkflowTesting/Sources/WorkflowActionTester.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,9 @@ extension WorkflowActionTester where WorkflowType.Output: Equatable {
190190
struct TestApplyContext<Wrapped: Workflow>: ApplyContextType {
191191
enum TestContextKind {
192192
case workflow(Wrapped)
193-
// TODO: flesh this out to support 'just in time' values
193+
// FIXME: flesh this out to support 'just in time' values
194194
// rather than requiring a full Workflow instance to be provided
195+
// https://github.com/square/workflow-swift/issues/351
195196
case expectations([AnyKeyPath: Any])
196197
}
197198

WorkflowTesting/Tests/WorkflowActionTesterTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ extension WorkflowActionTesterTests {
117117
.assert(output: .value("read props: 42"))
118118
}
119119

120-
// TODO: ideally an 'exit/death test' would be used for this...
120+
// FIXME: ideally an 'exit/death test' would somehow be used for this...
121121
/*
122122
func test_old_api_explodes_if_you_use_props() {
123123
XCTExpectFailure("This test should fail")

0 commit comments

Comments
 (0)