mirror of
https://github.com/yattee/yattee.git
synced 2024-12-12 21:30:32 +05:30
74b6adb247
Signed-off-by: Toni Förster <toni.foerster@gmail.com>
28 lines
847 B
Swift
28 lines
847 B
Swift
import Combine
|
|
import Foundation
|
|
|
|
final class MenuModel: ObservableObject {
|
|
static let shared = MenuModel()
|
|
private var cancellables = Set<AnyCancellable>()
|
|
|
|
init() {
|
|
registerChildModel(AccountsModel.shared)
|
|
registerChildModel(NavigationModel.shared)
|
|
registerChildModel(PlayerModel.shared)
|
|
}
|
|
|
|
func registerChildModel<T: ObservableObject>(_ model: T?) {
|
|
guard let model else {
|
|
return
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|