Slather logo

Coverage for "ActionToStepIntegrator.swift" : 100.00%

(21 of 21 relevant lines covered)

RouteComposer/Classes/Assemblies/Helpers/ActionToStepIntegrator.swift

1
//
2
// RouteComposer
3
// ActionToStepIntegrator.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
// This class is only needed not to expose `RoutingStep` as public.
17
/// A simple class that represents an intermediate `DestinationStep` and allows to add tasks to it.
18
public class IntermediateDestinationStep {
19
20
    // Hides action integration from library user.
21
    func routingStep(with action: some Action) -> RoutingStep? {
1x
22
        nil
1x
23
    }
1x
24
25
    // Hides action integration from library user.
26
    func embeddableRoutingStep(with action: some ContainerAction) -> RoutingStep? {
1x
27
        nil
1x
28
    }
1x
29
30
}
31
32
/// Allows to add tasks to the step that is hidden in `IntermediateDestinationStep`.
33
public class ActionToStepIntegrator<VC: UIViewController, C>: IntermediateDestinationStep, InterceptableStepAssembling {
34
35
    // MARK: Associated types
36
37
    public typealias ViewController = VC
38
39
    public typealias Context = C
40
41
    // MARK: Properties
42
43
    var taskCollector: TaskCollector
44
45
    // MARK: Methods
46
47
    init(taskCollector: TaskCollector = TaskCollector()) {
84x
48
        self.taskCollector = taskCollector
84x
49
    }
84x
50
51
    // MARK: Add a Task to the Step
52
53
    /// Adds `RoutingInterceptor` instance.
54
    /// This action does not contain type safety checks to avoid complications.
55
    ///
56
    /// - Parameter interceptor: The `RoutingInterceptor` instance to be executed by `Router` before the navigation process
57
    ///   to this step.
58
    public final func adding<RI: RoutingInterceptor>(_ interceptor: RI) -> Self where RI.Context == Context {
1x
59
        taskCollector.add(interceptor)
1x
60
        return self
1x
61
    }
1x
62
63
    /// Adds `ContextTask` instance
64
    ///
65
    /// - Parameter contextTask: The `ContextTask` instance to be applied by a `Router` immediately after it
66
    ///   will find or create `UIViewController`.
67
    public final func adding<CT: ContextTask>(_ contextTask: CT) -> Self
68
        where
69
        CT.ViewController == ViewController, CT.Context == Context {
4x
70
        taskCollector.add(contextTask)
4x
71
        return self
4x
72
    }
4x
73
74
    /// Adds `PostRoutingTask` instance.
75
    /// This action does not contain type safety checks to avoid complications.
76
    ///
77
    /// - Parameter postTask: The `PostRoutingTask` instance to be executed by a `Router` after the navigation process.
78
    public final func adding<PT: PostRoutingTask>(_ postTask: PT) -> Self where PT.Context == Context {
1x
79
        taskCollector.add(postTask)
1x
80
        return self
1x
81
    }
1x
82
83
}