Skip to content

Commit

Permalink
Merge pull request #1094 from square/bc/void-workflow
Browse files Browse the repository at this point in the history
Provide empty `makeInitialState` and `workflowDidChange` when State is Void
  • Loading branch information
bencochran committed Apr 16, 2020
2 parents a612008 + 23da9e0 commit 7a3ffec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
15 changes: 15 additions & 0 deletions swift/Workflow/Sources/Workflow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,21 @@ public protocol Workflow: AnyWorkflowConvertible {

}


/// When State is Void, provide empty `makeInitialState` and `workflowDidChange`
/// implementations, making a “stateless workflow”.
extension Workflow where State == Void {

public func makeInitialState() -> State {
return ()
}

public func workflowDidChange(from previousWorkflow: Self, state: inout State) {
}

}


extension Workflow {

public func asAnyWorkflow() -> AnyWorkflow<Rendering, Output> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@ fileprivate struct WrapperWorkflow<Rendering, Output>: Workflow {
self.wrapped = wrapped.asAnyWorkflow()
}

func makeInitialState() -> State {
return ()
}

func workflowDidChange(from previousWorkflow: WrapperWorkflow, state: inout State) {
}

func render(state: State, context: RenderContext<WrapperWorkflow>) -> Rendering {
return wrapped
.mapOutput { AnyWorkflowAction(sendingOutput: $0) }
Expand Down

0 comments on commit 7a3ffec

Please sign in to comment.