Skip to content

Commit bbe8b14

Browse files
committed
[feat]: add primary associated types to Workflow protocol
1 parent c8ac380 commit bbe8b14

File tree

1 file changed

+60
-26
lines changed

1 file changed

+60
-26
lines changed

Workflow/Sources/Workflow.swift

+60-26
Original file line numberDiff line numberDiff line change
@@ -49,37 +49,71 @@
4949
/// }
5050
/// ```
5151
///
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
5556

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
5859

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
6263

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
6768

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)
7374

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
83117

84118
extension Workflow {
85119
public func workflowDidChange(from previousWorkflow: Self, state: inout State) {}

0 commit comments

Comments
 (0)