[swiftui] - Makes changes to SwiftCurrent core in order to support SwiftUI - MOB
MODIFY
Sources/SwiftCurrent/Models/FlowRepresentableMetadata.swift
Sources/SwiftCurrent/Models/FlowRepresentableMetadata.swift
@@ -29,14 +29,29 @@ public class FlowRepresentableMetadata {
- Parameter launchStyle: the style to use when launching the `FlowRepresentable`.
- Parameter flowPersistence: a closure passing arguments to the caller and returning the preferred `FlowPersistence`.
*/
- public init<FR: FlowRepresentable>(_ flowRepresentableType: FR.Type,
+ public convenience init<FR: FlowRepresentable>(_ flowRepresentableType: FR.Type,
launchStyle: LaunchStyle = .default,
flowPersistence: @escaping (AnyWorkflow.PassedArgs) -> FlowPersistence) {
- flowRepresentableFactory = { args in
- AnyFlowRepresentable(FR.self, args: args)
+ self.init(flowRepresentableType,
+ launchStyle: launchStyle,
+ flowPersistence: flowPersistence) { args in
+ AnyFlowRepresentable(FR.self, args: args)}
}
- self.flowPersistence = flowPersistence
+
+ /**
+ Creates an instance that holds onto metadata associated with the `FlowRepresentable`.
+
+ - Parameter flowRepresentableType: specific type of the associated `FlowRepresentable`.
+ - Parameter launchStyle: the style to use when launching the `FlowRepresentable`.
+ - Parameter flowPersistence: a closure passing arguments to the caller and returning the preferred `FlowPersistence`.
+ */
+ public init<FR: FlowRepresentable>(_ flowRepresentableType: FR.Type,
+ launchStyle: LaunchStyle = .default,
+ flowPersistence: @escaping (AnyWorkflow.PassedArgs) -> FlowPersistence,
+ flowRepresentableFactory: @escaping (AnyWorkflow.PassedArgs) -> AnyFlowRepresentable) {
self.launchStyle = launchStyle
+ self.flowPersistence = flowPersistence
+ self.flowRepresentableFactory = flowRepresentableFactory
}
func setPersistence(_ args: AnyWorkflow.PassedArgs) -> FlowPersistence {

MODIFY
Sources/SwiftCurrent/TypeErased/AnyFlowRepresentable.swift
Sources/SwiftCurrent/TypeErased/AnyFlowRepresentable.swift
import Foundation
/// A type erased `FlowRepresentable`.
-public class AnyFlowRepresentable {
+open class AnyFlowRepresentable {
typealias WorkflowInput = Any
typealias WorkflowOutput = Any

MODIFY
Sources/SwiftCurrent/TypeErased/AnyWorkflow.swift
Sources/SwiftCurrent/TypeErased/AnyWorkflow.swift
@@ -35,6 +35,34 @@ public class AnyWorkflow {
// swiftlint:disable:next missing_docs
public func _abandon() { storageBase._abandon() }
+
+ /// Appends `FlowRepresentableMetadata` to the `Workflow`.
+ public func append(_ metadata: FlowRepresentableMetadata) {
+ storageBase.append(metadata)
+ }
+
+ /**
+ Launches the `Workflow`.
+
+ ### Discussion
+ passedArgs are passed to the first instance, it has the opportunity to load, not load and transform them, or just not load.
+ In the event an instance does not load and does not transform args, they are passed unmodified to the next instance in the `Workflow` until one loads.
+
+ - Parameter orchestrationResponder: the `OrchestrationResponder` to notify when the `Workflow` proceeds or backs up.
+ - Parameter passedArgs: the arguments to pass to the first instance(s).
+ - Parameter launchStyle: the launch style to use.
+ - Parameter onFinish: the closure to call when the last element in the workflow proceeds; called with the `AnyWorkflow.PassedArgs` the workflow finished with.
+ - Returns: the first loaded instance or nil, if none was loaded.
+ */
+ @discardableResult public func launch(withOrchestrationResponder orchestrationResponder: OrchestrationResponder,
+ passedArgs: AnyWorkflow.PassedArgs,
+ launchStyle: LaunchStyle = .default,
+ onFinish: ((AnyWorkflow.PassedArgs) -> Void)? = nil) -> AnyWorkflow.Element? {
+ storageBase.launch(withOrchestrationResponder: orchestrationResponder,
+ passedArgs: passedArgs,
+ launchStyle: launchStyle,
+ onFinish: onFinish)
+ }
}
extension AnyWorkflow: Sequence {
@@ -88,6 +116,21 @@ fileprivate class AnyWorkflowStorageBase {
func last(where _: (LinkedList<_WorkflowItem>.Element) throws -> Bool) rethrows -> LinkedList<_WorkflowItem>.Element? {
fatalError("last(where:) not overridden by AnyWorkflowStorage")
}
+
+ // https://github.com/wwt/SwiftCurrent/blob/main/.github/STYLEGUIDE.md#type-erasure
+ // swiftlint:disable:next unavailable_function
+ func append(_ metadata: FlowRepresentableMetadata) {
+ fatalError("append(:) not overriden")
+ }
+
+ // https://github.com/wwt/SwiftCurrent/blob/main/.github/STYLEGUIDE.md#type-erasure
+ // swiftlint:disable:next unavailable_function
+ @discardableResult public func launch(withOrchestrationResponder orchestrationResponder: OrchestrationResponder,
+ passedArgs: AnyWorkflow.PassedArgs,
+ launchStyle: LaunchStyle = .default,
+ onFinish: ((AnyWorkflow.PassedArgs) -> Void)? = nil) -> AnyWorkflow.Element? {
+ fatalError("launch(orchestrationResponder:passedArgs:launchStyle:onFinish) not overriden")
+ }
}
fileprivate final class AnyWorkflowStorage<F: FlowRepresentable>: AnyWorkflowStorageBase {
@@ -119,4 +162,18 @@ fileprivate final class AnyWorkflowStorage<F: FlowRepresentable>: AnyWorkflowSto
override func last(where predicate: (LinkedList<_WorkflowItem>.Element) throws -> Bool) rethrows -> LinkedList<_WorkflowItem>.Element? {
try workflow.last(where: predicate)
}
+
+ override func append(_ metadata: FlowRepresentableMetadata) {
+ workflow.append(metadata)
+ }
+
+ override func launch(withOrchestrationResponder orchestrationResponder: OrchestrationResponder,
+ passedArgs: AnyWorkflow.PassedArgs,
+ launchStyle: LaunchStyle = .default,
+ onFinish: ((AnyWorkflow.PassedArgs) -> Void)? = nil) -> AnyWorkflow.Element? {
+ workflow.launch(withOrchestrationResponder: orchestrationResponder,
+ passedArgs: passedArgs,
+ launchStyle: launchStyle,
+ onFinish: onFinish)
+ }
}

MODIFY
SwiftCurrent.xcworkspace/xcshareddata/xcschemes/SwiftCurrent.xcscheme
SwiftCurrent.xcworkspace/xcshareddata/xcschemes/SwiftCurrent.xcscheme
ReferencedContainer = "container:SwiftCurrentExample/SwiftCurrentExample.xcodeproj">
</BuildableReference>
</TestableReference>
+ <TestableReference
+ skipped = "NO">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "SwiftCurrent_SwiftUITests"
+ BuildableName = "SwiftCurrent_SwiftUITests"
+ BlueprintName = "SwiftCurrent_SwiftUITests"
+ ReferencedContainer = "container:">
+ </BuildableReference>
+ </TestableReference>
</Testables>
</TestAction>
<LaunchAction

[swiftui] - Makes changes to SwiftCurrent core in order to support SwiftUI - MOB