Skip to content

Commit 56ce335

Browse files
committed
wip
1 parent 94ab006 commit 56ce335

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

Sources/IntrospectionSelector.swift

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
@_spi(Internals)
22
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?
45

5-
static var `default`: Self { .from(Target.self, selector: { $0 }) }
6+
@_spi(Internals)
7+
public static var `default`: Self { .from(Target.self, selector: { $0 }) }
68

79
@_spi(Internals)
810
public static func from<Entry: PlatformEntity>(_ entryType: Entry.Type, selector: @escaping (Entry) -> Target?) -> Self {
@@ -43,15 +45,30 @@ public struct IntrospectionSelector<Target: PlatformEntity> {
4345
}
4446
}
4547

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) }
4853
}
4954

5055
func callAsFunction(
5156
_ controller: IntrospectionPlatformViewController,
5257
_ scope: IntrospectionScope,
5358
_ anchorID: IntrospectionAnchorID
5459
) -> 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
5673
}
5774
}

0 commit comments

Comments
 (0)