Slather logo

Coverage for "ActionConnectingAssembly.swift" : 100.00%

(18 of 18 relevant lines covered)

RouteComposer/Classes/Assemblies/Helpers/ActionConnectingAssembly.swift

1
//
2
// RouteComposer
3
// ActionConnectingAssembly.swift
4
// https://github.com/ekazaev/route-composer
5
//
6
// Created by Eugene Kazaev in 2018-2022.
7
// Distributed under the MIT license.
8
//
9
// Become a sponsor:
10
// https://github.com/sponsors/ekazaev
11
//
12
13
import Foundation
14
import UIKit
15
16
/// Helper class to build a chain of steps. Can not be used directly.
17
public struct ActionConnectingAssembly<VC: UIViewController, C> {
18
19
    // MARK: Properties
20
21
    let previousSteps: [RoutingStep]
22
23
    let stepToFullFill: IntermediateDestinationStep
24
25
    // MARK: Methods
26
27
    init(stepToFullFill: IntermediateDestinationStep, previousSteps: [RoutingStep] = []) {
54x
28
        self.previousSteps = previousSteps
54x
29
        self.stepToFullFill = stepToFullFill
54x
30
    }
54x
31
32
    /// Connects previously provided step instance with an `Action`
33
    ///
34
    /// - Parameter action: `Action` instance to be used with a step.
35
    /// - Returns: `ChainAssembly` to continue building the chain.
36
    public func using(_ action: some Action) -> StepChainAssembly<VC, C> {
45x
37
        var previousSteps = previousSteps
45x
38
        if let routingStep = stepToFullFill.routingStep(with: action) {
45x
39
            previousSteps.append(routingStep)
45x
40
        }
45x
41
        return StepChainAssembly(previousSteps: previousSteps)
45x
42
    }
45x
43
44
    /// Connects previously provided step instance with an `Action`
45
    ///
46
    /// - Parameter action: `Action` instance to be used with a step.
47
    /// - Returns: `ChainAssembly` to continue building the chain.
48
    public func using<A: ContainerAction>(_ action: A) -> ContainerStepChainAssembly<A.ViewController, VC, C> {
9x
49
        var previousSteps = previousSteps
9x
50
        if let routingStep = stepToFullFill.embeddableRoutingStep(with: action) {
9x
51
            previousSteps.append(routingStep)
9x
52
        }
9x
53
        return ContainerStepChainAssembly(previousSteps: previousSteps)
9x
54
    }
9x
55
56
}