From 04b58226d354a81d892714d794cc561a8c3b1bb6 Mon Sep 17 00:00:00 2001 From: Muukii Date: Thu, 27 Mar 2025 17:16:38 +0900 Subject: [PATCH] Patch --- Sources/StateStruct/PropertyPath.swift | 25 +++++++++++++++++++++-- Sources/StateStruct/TrackingRuntime.swift | 9 ++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/Sources/StateStruct/PropertyPath.swift b/Sources/StateStruct/PropertyPath.swift index 6c53445..81f7c3d 100644 --- a/Sources/StateStruct/PropertyPath.swift +++ b/Sources/StateStruct/PropertyPath.swift @@ -1,5 +1,6 @@ -public struct PropertyPath: Equatable { +@DebugDescription +public struct PropertyPath: Equatable, CustomDebugStringConvertible { public struct Component: Equatable { @@ -11,7 +12,13 @@ public struct PropertyPath: Equatable { } - public var components: [Component] = [] + public var components: [Component] = [] { + didSet { + #if DEBUG + _joined = components.map { $0.value }.joined(separator: ".") + #endif + } + } public init() { @@ -26,5 +33,19 @@ public struct PropertyPath: Equatable { self.components.append(component) return self } + + #if DEBUG + private var _joined: String = "" + #endif + + #if DEBUG + public var debugDescription: String { + "\(_joined) \(components.count)" + } + #else + public var debugDescription: String { + "Components : \(components.count)" + } + #endif } diff --git a/Sources/StateStruct/TrackingRuntime.swift b/Sources/StateStruct/TrackingRuntime.swift index 28834c5..cd43e2b 100644 --- a/Sources/StateStruct/TrackingRuntime.swift +++ b/Sources/StateStruct/TrackingRuntime.swift @@ -11,8 +11,13 @@ public enum TrackingRuntime { trackingContext: borrowing _TrackingContext ) -> Value { - trackingContext.trackingResultRef?.accessorRead(path: trackingContext.path?.pushed(component)) - + if + let ref = trackingContext.trackingResultRef, + let path = trackingContext.path + { + ref.accessorRead(path: path.pushed(component)) + } + if var value = value as? TrackingObject, let ref = trackingContext.trackingResultRef { if value._tracking_context.trackingResultRef !== ref {