Cleanup debounce

This commit is contained in:
Thomas Ricouard 2023-04-03 13:53:41 +02:00
parent 14e91a680e
commit ab51d57648

View File

@ -14,31 +14,33 @@ class DisplaySettingsLocalValues: ObservableObject {
@Published var lineSpacing = Theme.shared.lineSpacing
@Published var fontSizeScale = Theme.shared.fontSizeScale
private let debouncesDelay: DispatchQueue.SchedulerTimeType.Stride = .seconds(0.5)
private var subscriptions = Set<AnyCancellable>()
init() {
$tintColor
.debounce(for: .seconds(0.5), scheduler: DispatchQueue.main)
.debounce(for: debouncesDelay, scheduler: DispatchQueue.main)
.sink(receiveValue: { newColor in Theme.shared.tintColor = newColor })
.store(in: &subscriptions)
$primaryBackgroundColor
.debounce(for: .seconds(0.5), scheduler: DispatchQueue.main)
.debounce(for: debouncesDelay, scheduler: DispatchQueue.main)
.sink(receiveValue: { newColor in Theme.shared.primaryBackgroundColor = newColor })
.store(in: &subscriptions)
$secondaryBackgroundColor
.debounce(for: .seconds(0.5), scheduler: DispatchQueue.main)
.debounce(for: debouncesDelay, scheduler: DispatchQueue.main)
.sink(receiveValue: { newColor in Theme.shared.secondaryBackgroundColor = newColor })
.store(in: &subscriptions)
$labelColor
.debounce(for: .seconds(0.5), scheduler: DispatchQueue.main)
.debounce(for: debouncesDelay, scheduler: DispatchQueue.main)
.sink(receiveValue: { newColor in Theme.shared.labelColor = newColor })
.store(in: &subscriptions)
$lineSpacing
.debounce(for: .seconds(0.5), scheduler: DispatchQueue.main)
.debounce(for: debouncesDelay, scheduler: DispatchQueue.main)
.sink(receiveValue: { newSpacing in Theme.shared.lineSpacing = newSpacing })
.store(in: &subscriptions)
$fontSizeScale
.debounce(for: .seconds(0.5), scheduler: DispatchQueue.main)
.debounce(for: debouncesDelay, scheduler: DispatchQueue.main)
.sink(receiveValue: { newScale in Theme.shared.fontSizeScale = newScale })
.store(in: &subscriptions)
}