From fbf6552076163c6bc16356f37279a1637a8ea099 Mon Sep 17 00:00:00 2001 From: Tomas Strba Date: Thu, 20 May 2021 16:28:25 +0200 Subject: [PATCH] TabViewModel released immediately from TabCollectionViewModel after its tab is closed --- .../TabBar/ViewModel/TabCollectionViewModel.swift | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/DuckDuckGo/TabBar/ViewModel/TabCollectionViewModel.swift b/DuckDuckGo/TabBar/ViewModel/TabCollectionViewModel.swift index 31555369ae..4f00472193 100644 --- a/DuckDuckGo/TabBar/ViewModel/TabCollectionViewModel.swift +++ b/DuckDuckGo/TabBar/ViewModel/TabCollectionViewModel.swift @@ -45,7 +45,11 @@ final class TabCollectionViewModel: NSObject { updateSelectedTabViewModel() } } - @Published private(set) var selectedTabViewModel: TabViewModel? + @Published private(set) var selectedTabViewModel: TabViewModel? { + didSet { + previouslySelectedTabViewModel = oldValue + } + } private weak var previouslySelectedTabViewModel: TabViewModel? @Published private(set) var canInsertLastRemovedTab: Bool = false @@ -61,7 +65,6 @@ final class TabCollectionViewModel: NSObject { subscribeToTabs() subscribeToLastRemovedTab() - subscribeToSelectedTabViewModel() if tabCollection.tabs.isEmpty { appendNewTab() @@ -318,14 +321,6 @@ final class TabCollectionViewModel: NSObject { } .store(in: &cancellables) } - private func subscribeToSelectedTabViewModel() { - $selectedTabViewModel - .scan((nil, nil)) { return ($0.1, $1) } - .sink { [weak self] (previouslySelectedTabViewModel, _) in - self?.previouslySelectedTabViewModel = previouslySelectedTabViewModel - }.store(in: &cancellables) - } - private func removeTabViewModels(_ removed: Set) { for tab in removed { tabViewModels[tab] = nil