Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide empty makeInitialState and workflowDidChange when State is Void #1094

Merged
merged 1 commit into from
Apr 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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