This commit is contained in:
David Roman 2023-06-04 18:09:52 +01:00
parent 8254af4549
commit 5d7885b2fb
No known key found for this signature in database
GPG Key ID: 7058646EEFCB70A7
1 changed files with 24 additions and 19 deletions

View File

@ -1,38 +1,43 @@
@_spi(Internals)
public struct IntrospectionSelector<Target: PlatformEntity> {
private var receiverSelector: (IntrospectionPlatformViewController, IntrospectionAnchorID) -> Target?
private var ancestorSelector: (IntrospectionPlatformViewController) -> Target?
@_spi(Internals)
public static var `default`: Self { .from(Target.self, selector: { $0 }) }
@_spi(Internals)
public func withAncestorSelector(
_ selector: @escaping (PlatformViewController) -> Target?
) -> Self {
var copy = self
copy.ancestorSelector = selector
return copy
}
@_spi(Internals)
public static func from<Entry: PlatformEntity>(_ entryType: Entry.Type, selector: @escaping (Entry) -> Target?) -> Self {
.init(
receiver: { controller, anchorID in
receiverSelector: { controller, anchorID in
controller.as(Entry.self)?.receiver(ofType: Entry.self, anchorID: anchorID).flatMap(selector)
},
ancestor: { controller in
ancestorSelector: { controller in
controller.as(Entry.self)?.ancestor(ofType: Entry.self).flatMap(selector)
}
)
}
init(
receiver: @escaping (IntrospectionPlatformViewController, IntrospectionAnchorID) -> Target?,
ancestor: @escaping (IntrospectionPlatformViewController) -> Target?
private var receiverSelector: (IntrospectionPlatformViewController, IntrospectionAnchorID) -> Target?
private var ancestorSelector: (IntrospectionPlatformViewController) -> Target?
private init(
receiverSelector: @escaping (IntrospectionPlatformViewController, IntrospectionAnchorID) -> Target?,
ancestorSelector: @escaping (IntrospectionPlatformViewController) -> Target?
) {
self.receiverSelector = receiver
self.ancestorSelector = ancestor
self.receiverSelector = receiverSelector
self.ancestorSelector = ancestorSelector
}
@_spi(Internals)
public func withReceiverSelector(_ selector: @escaping (PlatformViewController, IntrospectionAnchorID) -> Target?) -> Self {
var copy = self
copy.receiverSelector = selector
return copy
}
@_spi(Internals)
public func withAncestorSelector(_ selector: @escaping (PlatformViewController) -> Target?) -> Self {
var copy = self
copy.ancestorSelector = selector
return copy
}
func callAsFunction(