1 |
//
|
|
2 |
// RouteComposer
|
|
3 |
// SwitcherStep.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 |
protocol StepCaseResolver {
|
|
17 |
|
|
18 |
func resolve(with context: AnyContext) -> RoutingStep?
|
|
19 |
|
|
20 |
}
|
|
21 |
|
|
22 |
final class SwitcherStep: RoutingStep, ChainableStep {
|
|
23 |
|
|
24 |
final var resolvers: [StepCaseResolver]
|
|
25 |
|
|
26 |
final func getPreviousStep(with context: AnyContext) -> RoutingStep? {
|
10x |
27 |
resolvers.reduce(nil as RoutingStep?) { result, resolver in
|
30x |
28 |
guard result == nil else {
|
30x |
29 |
return result
|
8x |
30 |
}
|
22x |
31 |
return resolver.resolve(with: context)
|
22x |
32 |
}
|
30x |
33 |
}
|
10x |
34 |
|
|
35 |
init(resolvers: [StepCaseResolver]) {
|
12x |
36 |
self.resolvers = resolvers
|
12x |
37 |
}
|
12x |
38 |
|
|
39 |
}
|
|