@@ -38,8 +38,8 @@ public struct ObservationRegistrar: Sendable {
38
38
39
39
private struct State : @unchecked Sendable {
40
40
private enum ObservationKind {
41
- case willSetTracking( @Sendable ( ) -> Void )
42
- case didSetTracking( @Sendable ( ) -> Void )
41
+ case willSetTracking( @Sendable ( AnyKeyPath ) -> Void )
42
+ case didSetTracking( @Sendable ( AnyKeyPath ) -> Void )
43
43
case computed( @Sendable ( Any ) -> Void )
44
44
case values( ValuesObserver )
45
45
}
@@ -53,7 +53,7 @@ public struct ObservationRegistrar: Sendable {
53
53
self . properties = properties
54
54
}
55
55
56
- var willSetTracker : ( @Sendable ( ) -> Void ) ? {
56
+ var willSetTracker : ( @Sendable ( AnyKeyPath ) -> Void ) ? {
57
57
switch kind {
58
58
case . willSetTracking( let tracker) :
59
59
return tracker
@@ -62,7 +62,7 @@ public struct ObservationRegistrar: Sendable {
62
62
}
63
63
}
64
64
65
- var didSetTracker : ( @Sendable ( ) -> Void ) ? {
65
+ var didSetTracker : ( @Sendable ( AnyKeyPath ) -> Void ) ? {
66
66
switch kind {
67
67
case . didSetTracking( let tracker) :
68
68
return tracker
@@ -117,7 +117,7 @@ public struct ObservationRegistrar: Sendable {
117
117
return id
118
118
}
119
119
120
- internal mutating func registerTracking( for properties: Set < AnyKeyPath > , willSet observer: @Sendable @escaping ( ) -> Void ) -> Int {
120
+ internal mutating func registerTracking( for properties: Set < AnyKeyPath > , willSet observer: @Sendable @escaping ( AnyKeyPath ) -> Void ) -> Int {
121
121
let id = generateId ( )
122
122
observations [ id] = Observation ( kind: . willSetTracking( observer) , properties: properties)
123
123
for keyPath in properties {
@@ -126,7 +126,7 @@ public struct ObservationRegistrar: Sendable {
126
126
return id
127
127
}
128
128
129
- internal mutating func registerTracking( for properties: Set < AnyKeyPath > , didSet observer: @Sendable @escaping ( ) -> Void ) -> Int {
129
+ internal mutating func registerTracking( for properties: Set < AnyKeyPath > , didSet observer: @Sendable @escaping ( AnyKeyPath ) -> Void ) -> Int {
130
130
let id = generateId ( )
131
131
observations [ id] = Observation ( kind: . didSetTracking( observer) , properties: properties)
132
132
for keyPath in properties {
@@ -184,8 +184,8 @@ public struct ObservationRegistrar: Sendable {
184
184
lookups. removeAll ( )
185
185
}
186
186
187
- internal mutating func willSet( keyPath: AnyKeyPath ) -> [ @Sendable ( ) -> Void ] {
188
- var trackers = [ @Sendable ( ) -> Void ] ( )
187
+ internal mutating func willSet( keyPath: AnyKeyPath ) -> [ @Sendable ( AnyKeyPath ) -> Void ] {
188
+ var trackers = [ @Sendable ( AnyKeyPath ) -> Void ] ( )
189
189
if let ids = lookups [ keyPath] {
190
190
for id in ids {
191
191
if let tracker = observations [ id] ? . willSetTracker {
@@ -196,9 +196,9 @@ public struct ObservationRegistrar: Sendable {
196
196
return trackers
197
197
}
198
198
199
- internal mutating func didSet< Subject: Observable , Member> ( keyPath: KeyPath < Subject , Member > ) -> ( [ @Sendable ( Any ) -> Void ] , [ @Sendable ( ) -> Void ] ) {
199
+ internal mutating func didSet< Subject: Observable , Member> ( keyPath: KeyPath < Subject , Member > ) -> ( [ @Sendable ( Any ) -> Void ] , [ @Sendable ( AnyKeyPath ) -> Void ] ) {
200
200
var observers = [ @Sendable ( Any ) -> Void ] ( )
201
- var trackers = [ @Sendable ( ) -> Void ] ( )
201
+ var trackers = [ @Sendable ( AnyKeyPath ) -> Void ] ( )
202
202
if let ids = lookups [ keyPath] {
203
203
for id in ids {
204
204
if let observer = observations [ id] ? . observer {
@@ -227,11 +227,11 @@ public struct ObservationRegistrar: Sendable {
227
227
228
228
internal var id : ObjectIdentifier { state. id }
229
229
230
- internal func registerTracking( for properties: Set < AnyKeyPath > , willSet observer: @Sendable @escaping ( ) -> Void ) -> Int {
230
+ internal func registerTracking( for properties: Set < AnyKeyPath > , willSet observer: @Sendable @escaping ( AnyKeyPath ) -> Void ) -> Int {
231
231
state. withCriticalRegion { $0. registerTracking ( for: properties, willSet: observer) }
232
232
}
233
233
234
- internal func registerTracking( for properties: Set < AnyKeyPath > , didSet observer: @Sendable @escaping ( ) -> Void ) -> Int {
234
+ internal func registerTracking( for properties: Set < AnyKeyPath > , didSet observer: @Sendable @escaping ( AnyKeyPath ) -> Void ) -> Int {
235
235
state. withCriticalRegion { $0. registerTracking ( for: properties, didSet: observer) }
236
236
}
237
237
@@ -257,7 +257,7 @@ public struct ObservationRegistrar: Sendable {
257
257
) {
258
258
let tracking = state. withCriticalRegion { $0. willSet ( keyPath: keyPath) }
259
259
for action in tracking {
260
- action ( )
260
+ action ( keyPath )
261
261
}
262
262
}
263
263
@@ -271,7 +271,7 @@ public struct ObservationRegistrar: Sendable {
271
271
state. withCriticalRegion { $0. emit ( value, ids: ids) }
272
272
}
273
273
for action in tracking {
274
- action ( )
274
+ action ( keyPath )
275
275
}
276
276
for action in actions {
277
277
action ( subject)
0 commit comments