mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Revert "[Observation] ensure event triggers on deinitialization passes as if …"
This reverts commit 9d1d917091.
This commit is contained in:
@@ -110,20 +110,9 @@ public struct ObservationRegistrar: Sendable {
|
||||
}
|
||||
}
|
||||
|
||||
internal mutating func deinitialize() -> [@Sendable () -> Void] {
|
||||
var trackers = [@Sendable () -> Void]()
|
||||
for (keyPath, ids) in lookups {
|
||||
for id in ids {
|
||||
if let tracker = observations[id]?.willSetTracker {
|
||||
trackers.append({
|
||||
tracker(keyPath)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
internal mutating func cancelAll() {
|
||||
observations.removeAll()
|
||||
lookups.removeAll()
|
||||
return trackers
|
||||
}
|
||||
|
||||
internal mutating func willSet(keyPath: AnyKeyPath) -> [@Sendable (AnyKeyPath) -> Void] {
|
||||
@@ -168,11 +157,8 @@ public struct ObservationRegistrar: Sendable {
|
||||
state.withCriticalRegion { $0.cancel(id) }
|
||||
}
|
||||
|
||||
internal func deinitialize() {
|
||||
let tracking = state.withCriticalRegion { $0.deinitialize() }
|
||||
for action in tracking {
|
||||
action()
|
||||
}
|
||||
internal func cancelAll() {
|
||||
state.withCriticalRegion { $0.cancelAll() }
|
||||
}
|
||||
|
||||
internal func willSet<Subject: Observable, Member>(
|
||||
@@ -203,7 +189,7 @@ public struct ObservationRegistrar: Sendable {
|
||||
}
|
||||
|
||||
deinit {
|
||||
context.deinitialize()
|
||||
context.cancelAll()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -287,21 +287,6 @@ final class CowTest {
|
||||
var container = CowContainer()
|
||||
}
|
||||
|
||||
@Observable
|
||||
final class DeinitTriggeredObserver {
|
||||
var property: Int = 3
|
||||
let deinitTrigger: () -> Void
|
||||
|
||||
init(_ deinitTrigger: @escaping () -> Void) {
|
||||
self.deinitTrigger = deinitTrigger
|
||||
}
|
||||
|
||||
deinit {
|
||||
deinitTrigger()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@main
|
||||
struct Validator {
|
||||
@MainActor
|
||||
@@ -526,22 +511,6 @@ struct Validator {
|
||||
expectEqual(subject.container.id, startId)
|
||||
}
|
||||
|
||||
suite.test("weak container observation") {
|
||||
let changed = CapturedState(state: false)
|
||||
let deinitialized = CapturedState(state: false)
|
||||
var test = DeinitTriggeredObserver {
|
||||
deinitialized.state = true
|
||||
}
|
||||
withObservationTracking { [weak test] in
|
||||
_blackHole(test?.property)
|
||||
} onChange: {
|
||||
changed.state = true
|
||||
}
|
||||
test = DeinitTriggeredObserver { }
|
||||
expectEqual(deinitialized.state, true)
|
||||
expectEqual(changed.state, true)
|
||||
}
|
||||
|
||||
runAllTests()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user