mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-25 09:41:00 +00:00
Prevent extra view model allocations
This commit is contained in:
parent
2b8f29d397
commit
668d4f2577
3 changed files with 15 additions and 10 deletions
|
@ -8,17 +8,28 @@ import ServiceLayer
|
|||
public final class NavigationViewModel: ObservableObject {
|
||||
public let identification: Identification
|
||||
@Published public private(set) var recentIdentities = [Identity]()
|
||||
@Published public var timeline: Timeline
|
||||
@Published public var timeline: Timeline {
|
||||
didSet {
|
||||
timelineViewModel = CollectionItemsViewModel(
|
||||
collectionService: identification.service.service(timeline: timeline),
|
||||
identification: identification)
|
||||
}
|
||||
}
|
||||
@Published public private(set) var timelinesAndLists: [Timeline]
|
||||
@Published public var presentingSecondaryNavigation = false
|
||||
@Published public var alertItem: AlertItem?
|
||||
public var selectedTab: Tab? = .timelines
|
||||
public private(set) var timelineViewModel: CollectionItemsViewModel
|
||||
|
||||
private var cancellables = Set<AnyCancellable>()
|
||||
|
||||
public init(identification: Identification) {
|
||||
self.identification = identification
|
||||
timeline = identification.identity.authenticated ? .home : .local
|
||||
let timeline: Timeline = identification.identity.authenticated ? .home : .local
|
||||
self.timeline = timeline
|
||||
timelineViewModel = CollectionItemsViewModel(
|
||||
collectionService: identification.service.service(timeline: timeline),
|
||||
identification: identification)
|
||||
timelinesAndLists = identification.identity.authenticated
|
||||
? Timeline.authenticatedDefaults
|
||||
: Timeline.unauthenticatedDefaults
|
||||
|
@ -89,12 +100,6 @@ public extension NavigationViewModel {
|
|||
.sink { _ in } receiveValue: { _ in }
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
func viewModel(timeline: Timeline) -> CollectionItemsViewModel {
|
||||
CollectionItemsViewModel(
|
||||
collectionService: identification.service.service(timeline: timeline),
|
||||
identification: identification)
|
||||
}
|
||||
}
|
||||
|
||||
public extension NavigationViewModel {
|
||||
|
|
|
@ -60,7 +60,7 @@ private extension TabNavigationView {
|
|||
func view(tab: NavigationViewModel.Tab) -> some View {
|
||||
switch tab {
|
||||
case .timelines:
|
||||
TableView(viewModel: viewModel.viewModel(timeline: viewModel.timeline))
|
||||
TableView(viewModel: viewModel.timelineViewModel)
|
||||
.id(viewModel.timeline.id)
|
||||
.edgesIgnoringSafeArea(.all)
|
||||
.navigationTitle(viewModel.timeline.title)
|
||||
|
|
|
@ -21,7 +21,7 @@ import PreviewViewModels
|
|||
|
||||
struct StatusListView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
TableView(viewModel: NavigationViewModel(identification: .preview).viewModel(timeline: .home))
|
||||
TableView(viewModel: NavigationViewModel(identification: .preview).timelineViewModel)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue