|
49 | 49 | /// }
|
50 | 50 | /// ```
|
51 | 51 | ///
|
| 52 | +#if swift(>=5.7) |
| 53 | +public protocol Workflow<Rendering, Output>: AnyWorkflowConvertible { |
| 54 | + /// Defines the state that is managed by this workflow. |
| 55 | + associatedtype State |
| 56 | + |
| 57 | + /// `Output` defines the type that can be emitted as output events. |
| 58 | + associatedtype Output = Never |
| 59 | + |
| 60 | + /// `Rendering` is the type that is produced by the `render` method: it |
| 61 | + /// is commonly a view / screen model. |
| 62 | + associatedtype Rendering |
| 63 | + |
| 64 | + /// This method is invoked once when a workflow node comes into existence. |
| 65 | + /// |
| 66 | + /// - Returns: The initial state for the workflow. |
| 67 | + func makeInitialState() -> State |
| 68 | + |
| 69 | + /// Called when a new workflow is passed down from the parent to an existing workflow node. |
| 70 | + /// |
| 71 | + /// - Parameter previousWorkflow: The workflow before the update. |
| 72 | + /// - Parameter state: The current state. |
| 73 | + func workflowDidChange(from previousWorkflow: Self, state: inout State) |
| 74 | + |
| 75 | + /// Called by the internal Workflow infrastructure to "render" the current state into `Rendering`. |
| 76 | + /// A workflow's `Rendering` type is commonly a view or screen model. |
| 77 | + /// |
| 78 | + /// - Parameter state: The current state. |
| 79 | + /// - Parameter context: The workflow context is the composition point for the workflow tree. To use a nested |
| 80 | + /// workflow, instantiate it based on the current state, then call `rendered(in:key:outputMap:)`. |
| 81 | + /// This will return the child's `Rendering` type after creating or updating the nested workflow. |
| 82 | + func render(state: State, context: RenderContext<Self>) -> Rendering |
| 83 | +} |
| 84 | +#else |
52 | 85 | public protocol Workflow: AnyWorkflowConvertible {
|
53 | 86 | /// Defines the state that is managed by this workflow.
|
54 | 87 | associatedtype State
|
@@ -80,6 +113,7 @@ public protocol Workflow: AnyWorkflowConvertible {
|
80 | 113 | /// This will return the child's `Rendering` type after creating or updating the nested workflow.
|
81 | 114 | func render(state: State, context: RenderContext<Self>) -> Rendering
|
82 | 115 | }
|
| 116 | +#endif |
83 | 117 |
|
84 | 118 | extension Workflow {
|
85 | 119 | public func workflowDidChange(from previousWorkflow: Self, state: inout State) {}
|
|
0 commit comments