File tree Expand file tree Collapse file tree 2 files changed +4
-49
lines changed
stdlib/public/Observation/Sources/Observation Expand file tree Collapse file tree 2 files changed +4
-49
lines changed Original file line number Diff line number Diff line change @@ -110,20 +110,9 @@ public struct ObservationRegistrar: Sendable {
110
110
}
111
111
}
112
112
113
- internal mutating func deinitialize( ) -> [ @Sendable ( ) -> Void ] {
114
- var trackers = [ @Sendable ( ) -> Void ] ( )
115
- for (keyPath, ids) in lookups {
116
- for id in ids {
117
- if let tracker = observations [ id] ? . willSetTracker {
118
- trackers. append ( {
119
- tracker ( keyPath)
120
- } )
121
- }
122
- }
123
- }
113
+ internal mutating func cancelAll( ) {
124
114
observations. removeAll ( )
125
115
lookups. removeAll ( )
126
- return trackers
127
116
}
128
117
129
118
internal mutating func willSet( keyPath: AnyKeyPath ) -> [ @Sendable ( AnyKeyPath ) -> Void ] {
@@ -168,11 +157,8 @@ public struct ObservationRegistrar: Sendable {
168
157
state. withCriticalRegion { $0. cancel ( id) }
169
158
}
170
159
171
- internal func deinitialize( ) {
172
- let tracking = state. withCriticalRegion { $0. deinitialize ( ) }
173
- for action in tracking {
174
- action ( )
175
- }
160
+ internal func cancelAll( ) {
161
+ state. withCriticalRegion { $0. cancelAll ( ) }
176
162
}
177
163
178
164
internal func willSet< Subject: Observable , Member> (
@@ -203,7 +189,7 @@ public struct ObservationRegistrar: Sendable {
203
189
}
204
190
205
191
deinit {
206
- context. deinitialize ( )
192
+ context. cancelAll ( )
207
193
}
208
194
}
209
195
Original file line number Diff line number Diff line change @@ -287,21 +287,6 @@ final class CowTest {
287
287
var container = CowContainer ( )
288
288
}
289
289
290
- @Observable
291
- final class DeinitTriggeredObserver {
292
- var property : Int = 3
293
- let deinitTrigger : ( ) -> Void
294
-
295
- init ( _ deinitTrigger: @escaping ( ) -> Void ) {
296
- self . deinitTrigger = deinitTrigger
297
- }
298
-
299
- deinit {
300
- deinitTrigger ( )
301
- }
302
- }
303
-
304
-
305
290
@main
306
291
struct Validator {
307
292
@MainActor
@@ -526,22 +511,6 @@ struct Validator {
526
511
expectEqual ( subject. container. id, startId)
527
512
}
528
513
529
- suite. test ( " weak container observation " ) {
530
- let changed = CapturedState ( state: false )
531
- let deinitialized = CapturedState ( state: false )
532
- var test = DeinitTriggeredObserver {
533
- deinitialized. state = true
534
- }
535
- withObservationTracking { [ weak test] in
536
- _blackHole ( test? . property)
537
- } onChange: {
538
- changed. state = true
539
- }
540
- test = DeinitTriggeredObserver { }
541
- expectEqual ( deinitialized. state, true )
542
- expectEqual ( changed. state, true )
543
- }
544
-
545
514
runAllTests ( )
546
515
}
547
516
}
You can’t perform that action at this time.
0 commit comments