Save automatically, improve mocks
This commit is contained in:
31
CHDataManagement/Storage/ChangeObservableItem.swift
Normal file
31
CHDataManagement/Storage/ChangeObservableItem.swift
Normal file
@ -0,0 +1,31 @@
|
||||
import Combine
|
||||
|
||||
protocol ChangeObservableItem: ObservableObject {
|
||||
|
||||
var cancellables: Set<AnyCancellable> { get set }
|
||||
|
||||
func needsSaving()
|
||||
}
|
||||
|
||||
protocol ObservableContentItem: ChangeObservableItem {
|
||||
|
||||
var content: Content { get }
|
||||
}
|
||||
|
||||
extension ObservableContentItem {
|
||||
|
||||
func needsSaving() {
|
||||
content.needsSave()
|
||||
}
|
||||
}
|
||||
|
||||
extension ChangeObservableItem {
|
||||
|
||||
func observeChanges() {
|
||||
objectWillChange
|
||||
.sink { [weak self] _ in
|
||||
self?.needsSaving()
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user