Skip to content

Commit 5e6c608

Browse files
committed
Using cancelables so workspace cleanup is more concise
1 parent 749c716 commit 5e6c608

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

CodeEdit/Features/Documents/WorkspaceDocument/WorkspaceDocument.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,23 @@ final class WorkspaceDocument: NSDocument, ObservableObject, NSToolbarDelegate {
4444
var taskNotificationHandler: TaskNotificationHandler = TaskNotificationHandler()
4545

4646
@Published var notificationPanel = NotificationPanelViewModel()
47-
private var notificationPanelSubscription: AnyCancellable?
48-
4947
private var cancellables = Set<AnyCancellable>()
5048

5149
override init() {
5250
super.init()
5351

5452
// Observe changes to notification panel
55-
notificationPanelSubscription = notificationPanel.objectWillChange
53+
notificationPanel.objectWillChange
5654
.receive(on: DispatchQueue.main)
5755
.sink { [weak self] _ in
5856
self?.objectWillChange.send()
5957
}
58+
.store(in: &cancellables)
6059
}
6160

6261
deinit {
6362
cancellables.forEach { $0.cancel() }
6463
NotificationCenter.default.removeObserver(self)
65-
notificationPanelSubscription?.cancel()
6664
}
6765

6866
func getFromWorkspaceState(_ key: WorkspaceStateKey) -> Any? {

0 commit comments

Comments
 (0)