Slather logo

Coverage for "GenericStepAssembly.swift" : 100.00%

(13 of 13 relevant lines covered)

RouteComposer/Classes/Assemblies/Helpers/GenericStepAssembly.swift

1
//
2
// RouteComposer
3
// GenericStepAssembly.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
/// Abstract builder class that helps to create a `DestinationStep` instance with correct settings.
17
public class GenericStepAssembly<VC: UIViewController, C>: InterceptableStepAssembling {
18
19
    // MARK: Associated types
20
21
    public typealias ViewController = VC
22
23
    public typealias Context = C
24
25
    // MARK: Properties
26
27
    var taskCollector = TaskCollector()
194x
28
29
    // MARK: Add a Task to the Step
30
31
    /// Adds `RoutingInterceptor` instance.
32
    /// This action does not contain type safety checks to avoid complications.
33
    ///
34
    /// - Parameter interceptor: The `RoutingInterceptor` instance to be executed by `Router` before the navigation process
35
    ///   to this step.
36
    public final func adding<RI: RoutingInterceptor>(_ interceptor: RI) -> Self where RI.Context == Context {
22x
37
        taskCollector.add(interceptor)
22x
38
        return self
22x
39
    }
22x
40
41
    /// Adds `ContextTask` instance
42
    ///
43
    /// - Parameter contextTask: The `ContextTask` instance to be applied by a `Router` immediately after it
44
    ///   will find or create `UIViewController`.
45
    public final func adding<CT: ContextTask>(_ contextTask: CT) -> Self
46
        where
47
        CT.ViewController == ViewController, CT.Context == Context {
113x
48
        taskCollector.add(contextTask)
113x
49
        return self
113x
50
    }
113x
51
52
    /// Adds `PostRoutingTask` instance.
53
    /// This action does not contain type safety checks to avoid complications.
54
    ///
55
    /// - Parameter postTask: The `PostRoutingTask` instance to be executed by a `Router` after the navigation process.
56
    public final func adding<PT: PostRoutingTask>(_ postTask: PT) -> Self where PT.Context == Context {
10x
57
        taskCollector.add(postTask)
10x
58
        return self
10x
59
    }
10x
60
61
}