Skip to content

Commit e13aa73

Browse files
authored
Add DebugDescription (#37)
1 parent fc60fbc commit e13aa73

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

Sources/StateStruct/PropertyPath.swift

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

2-
public struct PropertyPath: Equatable {
2+
@DebugDescription
3+
public struct PropertyPath: Equatable, CustomDebugStringConvertible {
34

45
public struct Component: Equatable {
56

@@ -11,7 +12,13 @@ public struct PropertyPath: Equatable {
1112

1213
}
1314

14-
public var components: [Component] = []
15+
public var components: [Component] = [] {
16+
didSet {
17+
#if DEBUG
18+
_joined = components.map { $0.value }.joined(separator: ".")
19+
#endif
20+
}
21+
}
1522

1623
public init() {
1724

@@ -26,5 +33,19 @@ public struct PropertyPath: Equatable {
2633
self.components.append(component)
2734
return self
2835
}
36+
37+
#if DEBUG
38+
private var _joined: String = ""
39+
#endif
40+
41+
#if DEBUG
42+
public var debugDescription: String {
43+
"\(_joined) \(components.count)"
44+
}
45+
#else
46+
public var debugDescription: String {
47+
"Components : \(components.count)"
48+
}
49+
#endif
2950

3051
}

Sources/StateStruct/TrackingRuntime.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@ public enum TrackingRuntime {
1111
trackingContext: borrowing _TrackingContext
1212
) -> Value {
1313

14-
trackingContext.trackingResultRef?.accessorRead(path: trackingContext.path?.pushed(component))
15-
14+
if
15+
let ref = trackingContext.trackingResultRef,
16+
let path = trackingContext.path
17+
{
18+
ref.accessorRead(path: path.pushed(component))
19+
}
20+
1621
if var value = value as? TrackingObject, let ref = trackingContext.trackingResultRef {
1722

1823
if value._tracking_context.trackingResultRef !== ref {

0 commit comments

Comments
 (0)