Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions App/AppState 2.swift

This file was deleted.

22 changes: 13 additions & 9 deletions App/AppState.swift
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
/* import SwiftUI

final class AppState: ObservableObject {
@Published var plannerVM = MealPlannerViewModel()
@Published var goalsVM = GoalsViewModel()
@Published var historyVM = HistoryViewModel()
} */

import SwiftUI
import Combine

final class AppState: ObservableObject {

let plannerVM: MealPlannerViewModel
let goalsVM: GoalsViewModel
let historyVM: HistoryViewModel

private var cancellables = Set<AnyCancellable>()

init() {
self.plannerVM = MealPlannerViewModel()
self.goalsVM = GoalsViewModel()
self.goalsVM = GoalsViewModel()
self.historyVM = HistoryViewModel()

// Keep GoalsViewModel in sync whenever plannerVM publishes any change.
plannerVM.objectWillChange
.receive(on: DispatchQueue.main)
.sink { [weak self] _ in
guard let self else { return }
self.goalsVM.sync(from: self.plannerVM)
}
.store(in: &cancellables)
}
}
1 change: 1 addition & 0 deletions ViewModels/Goals/GoalsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ final class GoalsViewModel: ObservableObject {
currentProtein = planner.currentProtein
currentCarbs = planner.currentCarbs
currentFat = planner.currentFat
goals = planner.goals
}
}
Loading
Loading