-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove the need to type-erase publisher to render the workflow view
- Loading branch information
1 parent
2b727df
commit 1f971a8
Showing
8 changed files
with
50 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// Publisher+Extensions.swift | ||
// WorkflowCombine | ||
// | ||
// Created by Soo Rin Park on 11/3/21. | ||
// | ||
|
||
#if canImport(Combine) && swift(>=5.1) | ||
|
||
import Combine | ||
import Foundation | ||
import Workflow | ||
|
||
@available(iOS 13.0, macOS 10.15, *) | ||
/// This is a workaround to the fact you extensions of protocols cannot have an inheritance clause. | ||
/// a previous solution had extending the `AnyPublisher` to conform to `AnyWorkflowConvertible`, | ||
/// but was limited in the fact that rendering was only available to `AnyPublisher`s. | ||
/// this solutions makes it so that all publishers can render its view. | ||
extension Publisher where Failure == Never { | ||
public func running<Parent>(in context: RenderContext<Parent>, key: String = "") where | ||
Output == AnyWorkflowAction<Parent> { | ||
asAnyWorkflow().rendered(in: context, key: key, outputMap: { $0 }) | ||
} | ||
|
||
public func mapOutput<NewOutput>(_ transform: @escaping (Output) -> NewOutput) -> AnyWorkflow<Void, NewOutput> { | ||
asAnyWorkflow().mapOutput(transform) | ||
} | ||
|
||
func asAnyWorkflow() -> AnyWorkflow<Void, Output> { | ||
PublisherWorkflow(publisher: self).asAnyWorkflow() | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters