Ensure unused publishers are canceled

This commit is contained in:
Justin Mazzocchi 2021-01-27 18:05:15 -08:00
parent 555d436cf5
commit aa08b9b284
No known key found for this signature in database
GPG Key ID: E223E6937AAFB01C
1 changed files with 3 additions and 2 deletions

View File

@ -14,6 +14,7 @@ public final class RootViewModel: ObservableObject {
private let userNotificationService: UserNotificationService
private let registerForRemoteNotifications: () -> AnyPublisher<Data, Error>
private var cancellables = Set<AnyCancellable>()
private var navigationViewModelCancellable: AnyCancellable?
public init(environment: AppEnvironment,
registerForRemoteNotifications: @escaping () -> AnyPublisher<Data, Error>) throws {
@ -95,7 +96,7 @@ private extension RootViewModel {
}
.share()
identityPublisher
navigationViewModelCancellable = identityPublisher
.filter { [weak self] in $0.id != self?.navigationViewModel?.identityContext.identity.id }
.map { [weak self] in
guard let self = self else { return nil }
@ -121,6 +122,6 @@ private extension RootViewModel {
return NavigationViewModel(identityContext: identityContext)
}
.assign(to: &$navigationViewModel)
.sink { [weak self] in self?.navigationViewModel = $0 }
}
}