1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
import Foundation
|
|
14 |
import UIKit
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
public struct InlineInterceptor<C>: RoutingInterceptor {
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
private let prepareBlock: ((_: C) throws -> Void)?
|
|
25 |
|
|
26 |
private let performBlock: (_: C, _: @escaping (RoutingResult) -> Void) -> Void
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
public init(prepare prepareBlock: ((_: C) throws -> Void)? = nil, _ performBlock: @escaping (_: C, _: @escaping (RoutingResult) -> Void) -> Void) {
|
3x |
36 |
self.prepareBlock = prepareBlock
|
3x |
37 |
self.performBlock = performBlock
|
3x |
38 |
}
|
3x |
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
public init(prepare prepareBlock: ((_: C) throws -> Void)? = nil, _ inlineBlock: @escaping (_: C) throws -> Void) {
|
14x |
47 |
self.prepareBlock = prepareBlock
|
14x |
48 |
self.performBlock = { context, completion in
|
14x |
49 |
do {
|
12x |
50 |
try inlineBlock(context)
|
12x |
51 |
completion(.success)
|
12x |
52 |
} catch {
|
12x |
53 |
completion(.failure(error))
|
1x |
54 |
}
|
12x |
55 |
}
|
12x |
56 |
}
|
14x |
57 |
|
|
58 |
public func prepare(with context: C) throws {
|
18x |
59 |
try prepareBlock?(context)
|
18x |
60 |
}
|
18x |
61 |
|
|
62 |
public func perform(with context: C, completion: @escaping (RoutingResult) -> Void) {
|
15x |
63 |
performBlock(context, completion)
|
15x |
64 |
}
|
15x |
65 |
|
|
66 |
}
|
|