|
1 | 1 | @_spi(Internals)
|
2 | 2 | public struct IntrospectionSelector<Target: PlatformEntity> {
|
3 |
| - private let selector: (IntrospectionPlatformViewController, IntrospectionScope, IntrospectionAnchorID) -> Target? |
| 3 | + private var receiver: (IntrospectionPlatformViewController, IntrospectionAnchorID) -> Target? |
| 4 | + private var ancestor: (IntrospectionPlatformViewController, IntrospectionAnchorID) -> Target? |
4 | 5 |
|
5 |
| - static var `default`: Self { .from(Target.self, selector: { $0 }) } |
| 6 | + @_spi(Internals) |
| 7 | + public static var `default`: Self { .from(Target.self, selector: { $0 }) } |
6 | 8 |
|
7 | 9 | @_spi(Internals)
|
8 | 10 | public static func from<Entry: PlatformEntity>(_ entryType: Entry.Type, selector: @escaping (Entry) -> Target?) -> Self {
|
@@ -43,15 +45,30 @@ public struct IntrospectionSelector<Target: PlatformEntity> {
|
43 | 45 | }
|
44 | 46 | }
|
45 | 47 |
|
46 |
| - init(_ selector: @escaping (IntrospectionPlatformViewController, IntrospectionScope, IntrospectionAnchorID) -> Target?) { |
47 |
| - self.selector = selector |
| 48 | + init( |
| 49 | + _ selector: @escaping (IntrospectionPlatformViewController, IntrospectionScope, IntrospectionAnchorID) -> Target? |
| 50 | + ) { |
| 51 | + self.receiver = { selector($0, .receiver, $1) } |
| 52 | + self.ancestor = { selector($0, .ancestor, $1) } |
48 | 53 | }
|
49 | 54 |
|
50 | 55 | func callAsFunction(
|
51 | 56 | _ controller: IntrospectionPlatformViewController,
|
52 | 57 | _ scope: IntrospectionScope,
|
53 | 58 | _ anchorID: IntrospectionAnchorID
|
54 | 59 | ) -> Target? {
|
55 |
| - selector(controller, scope, anchorID) |
| 60 | + if |
| 61 | + scope.contains(.receiver), |
| 62 | + let target = receiver(controller, anchorID) |
| 63 | + { |
| 64 | + return target |
| 65 | + } |
| 66 | + if |
| 67 | + scope.contains(.ancestor), |
| 68 | + let target = ancestor(controller, anchorID) |
| 69 | + { |
| 70 | + return target |
| 71 | + } |
| 72 | + return nil |
56 | 73 | }
|
57 | 74 | }
|
0 commit comments