If I have a type like this:
final class SearchModel: ObservableObject {
@Published var input = ""
@Published var scope = ""
@Published private(set) var results: [SearchResult] = []
init() {
Publishers.CombineLatest($input, $scope)
//.debounce(for: .milliseconds(300), scheduler: RunLoop.main)
.removeDuplicates(by: ==)
.map { search(for: $0, in: $1) }
.switchToLatest()
.assign(to: &$results)
}
}
struct SearchView: View {
@StateObject var model = SearchModel()
var body: some View {
// bind $model.input, $model.scope to text fields,
// present model.results
}
}
Will this proposed API be suitable to replace Combine in this case? Can I use continuous observation tracking to make an @Observable model react to changes to input and scope, to produce some result that isn't merely a computed property of its inputs?
Can I use it to also implement some kind of debouncer on user input, to allow the user to type fast and only search when slowing down?
I'm not arguing for dropping Combine for the sake of dropping it, but merely want to understand how Published.Publisher is overlapping with the proposed APIs, if at all.