1 |
//
|
|
2 |
// RouteComposer
|
|
3 |
// AnyFactoryBox.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 |
|
|
15 |
protocol AnyFactoryBox: AnyFactory {
|
|
16 |
|
|
17 |
associatedtype FactoryType: AbstractFactory
|
|
18 |
|
|
19 |
var factory: FactoryType { get set }
|
|
20 |
|
|
21 |
init?(_ factory: FactoryType, action: AnyAction)
|
|
22 |
|
|
23 |
}
|
|
24 |
|
|
25 |
protocol PreparableAnyFactory: AnyFactory, PreparableEntity {
|
|
26 |
|
|
27 |
var isPrepared: Bool { get set }
|
|
28 |
|
|
29 |
}
|
|
30 |
|
|
31 |
extension AnyFactoryBox {
|
|
32 |
|
|
33 |
mutating func scrapeChildren(from factories: [(factory: AnyFactory, context: AnyContext)]) throws -> [(factory: AnyFactory, context: AnyContext)] {
|
107x |
34 |
factories
|
107x |
35 |
}
|
107x |
36 |
|
|
37 |
}
|
|
38 |
|
|
39 |
extension AnyFactoryBox where Self: PreparableAnyFactory, Self: MainThreadChecking {
|
|
40 |
|
|
41 |
mutating func prepare(with context: AnyContext) throws {
|
170x |
42 |
assertIfNotMainThread()
|
170x |
43 |
let typedContext: FactoryType.Context = try context.value()
|
170x |
44 |
try factory.prepare(with: typedContext)
|
170x |
45 |
isPrepared = true
|
170x |
46 |
}
|
170x |
47 |
|
|
48 |
}
|
|
49 |
|
|
50 |
extension AnyFactory where Self: CustomStringConvertible & AnyFactoryBox {
|
|
51 |
|
|
52 |
var description: String {
|
424x |
53 |
String(describing: factory)
|
424x |
54 |
}
|
424x |
55 |
|
|
56 |
}
|
|