2021-11-09 04:44:28 +05:30
|
|
|
import Combine
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
final class MenuModel: ObservableObject {
|
2022-11-25 02:06:05 +05:30
|
|
|
static let shared = MenuModel()
|
2024-08-26 03:11:06 +05:30
|
|
|
private var cancellables = Set<AnyCancellable>()
|
2021-11-09 04:44:28 +05:30
|
|
|
|
2022-11-25 02:06:05 +05:30
|
|
|
init() {
|
|
|
|
registerChildModel(AccountsModel.shared)
|
|
|
|
registerChildModel(NavigationModel.shared)
|
|
|
|
registerChildModel(PlayerModel.shared)
|
|
|
|
}
|
|
|
|
|
2021-11-09 04:44:28 +05:30
|
|
|
func registerChildModel<T: ObservableObject>(_ model: T?) {
|
2024-08-26 03:11:06 +05:30
|
|
|
guard let model else {
|
2021-11-09 04:44:28 +05:30
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-08-26 03:11:06 +05:30
|
|
|
model.objectWillChange
|
|
|
|
.receive(on: DispatchQueue.main) // Ensure the update occurs on the main thread
|
|
|
|
.debounce(for: .milliseconds(10), scheduler: DispatchQueue.main) // Debounce to avoid immediate feedback loops
|
|
|
|
.sink { [weak self] _ in
|
|
|
|
self?.objectWillChange.send()
|
|
|
|
}
|
|
|
|
.store(in: &cancellables)
|
2021-11-09 04:44:28 +05:30
|
|
|
}
|
|
|
|
}
|