Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
davdroman committed Jul 16, 2024
1 parent 3b2ba65 commit cfc3c30
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 18 deletions.
12 changes: 0 additions & 12 deletions Sources/Introspect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,46 +103,37 @@ public protocol PlatformEntity: AnyObject {
associatedtype Base: PlatformEntity

@_spi(Internals)
@MainActor
var ancestor: Base? { get }

@_spi(Internals)
@MainActor
var descendants: [Base] { get }

@_spi(Internals)
@MainActor
func isDescendant(of other: Base) -> Bool
}

extension PlatformEntity {
@_spi(Internals)
@MainActor
public var ancestor: Base? { nil }

@_spi(Internals)
@MainActor
public var descendants: [Base] { [] }

@_spi(Internals)
@MainActor
public func isDescendant(of other: Base) -> Bool { false }
}

extension PlatformEntity {
@_spi(Internals)
@MainActor
public var ancestors: some Sequence<Base> {
sequence(first: self~, next: { $0.ancestor~ }).dropFirst()
}

@_spi(Internals)
@MainActor
public var allDescendants: some Sequence<Base> {
recursiveSequence([self~], children: { $0.descendants~ }).dropFirst()
}

@MainActor
func nearestCommonAncestor(with other: Base) -> Base? {
var nearestAncestor: Base? = self~

Expand All @@ -153,15 +144,13 @@ extension PlatformEntity {
return nearestAncestor
}

@MainActor
func allDescendants(between bottomEntity: Base, and topEntity: Base) -> some Sequence<Base> {
self.allDescendants
.lazy
.drop(while: { $0 !== bottomEntity })
.prefix(while: { $0 !== topEntity })
}

@MainActor
func receiver<PlatformSpecificEntity: PlatformEntity>(
ofType type: PlatformSpecificEntity.Type
) -> PlatformSpecificEntity? {
Expand All @@ -180,7 +169,6 @@ extension PlatformEntity {
.first
}

@MainActor
func ancestor<PlatformSpecificEntity: PlatformEntity>(
ofType type: PlatformSpecificEntity.Type
) -> PlatformSpecificEntity? {
Expand Down
3 changes: 0 additions & 3 deletions Sources/IntrospectionSelector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
@MainActor
public struct IntrospectionSelector<Target: PlatformEntity> {
@_spi(Advanced)
@MainActor
public static var `default`: Self { .from(Target.self, selector: { $0 }) }

@_spi(Advanced)
@MainActor
public static func from<Entry: PlatformEntity>(_ entryType: Entry.Type, selector: @MainActor @escaping (Entry) -> Target?) -> Self {
.init(
receiverSelector: { controller in
Expand Down Expand Up @@ -45,7 +43,6 @@ public struct IntrospectionSelector<Target: PlatformEntity> {
return copy
}

@MainActor
func callAsFunction(_ controller: IntrospectionPlatformViewController, _ scope: IntrospectionScope) -> Target? {
if
scope.contains(.receiver),
Expand Down
3 changes: 1 addition & 2 deletions Sources/IntrospectionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import SwiftUI

typealias IntrospectionViewID = UUID

@MainActor
fileprivate enum IntrospectionStore {
@MainActor
static var shared: [IntrospectionViewID: Pair] = [:]

struct Pair {
Expand All @@ -14,7 +14,6 @@ fileprivate enum IntrospectionStore {
}

extension PlatformEntity {
@MainActor
var introspectionAnchorEntity: Base? {
if let introspectionController = self as? IntrospectionPlatformViewController {
return IntrospectionStore.shared[introspectionController.id]?.anchor~
Expand Down
2 changes: 1 addition & 1 deletion Sources/ViewTypes/ListCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ import SwiftUI
/// }
/// ```
public struct ListCellType: IntrospectableViewType {
@MainActor public var scope: IntrospectionScope { .ancestor }
public var scope: IntrospectionScope { .ancestor }
}

extension IntrospectableViewType where Self == ListCellType {
Expand Down

0 comments on commit cfc3c30

Please sign in to comment.