From aa08b9b28444400475db8dfc5fcd272dc6aec173 Mon Sep 17 00:00:00 2001 From: Justin Mazzocchi <2831158+jzzocc@users.noreply.github.com> Date: Wed, 27 Jan 2021 18:05:15 -0800 Subject: [PATCH] Ensure unused publishers are canceled --- .../Sources/ViewModels/View Models/RootViewModel.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ViewModels/Sources/ViewModels/View Models/RootViewModel.swift b/ViewModels/Sources/ViewModels/View Models/RootViewModel.swift index 52ab8c0..c4b3c11 100644 --- a/ViewModels/Sources/ViewModels/View Models/RootViewModel.swift +++ b/ViewModels/Sources/ViewModels/View Models/RootViewModel.swift @@ -14,6 +14,7 @@ public final class RootViewModel: ObservableObject { private let userNotificationService: UserNotificationService private let registerForRemoteNotifications: () -> AnyPublisher private var cancellables = Set() + private var navigationViewModelCancellable: AnyCancellable? public init(environment: AppEnvironment, registerForRemoteNotifications: @escaping () -> AnyPublisher) 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 } } }