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