mirror of
https://github.com/ivanvorobei/SwiftUI.git
synced 2026-03-31 14:33:39 +02:00
Xcode 11 beta 6
This commit is contained in:
@@ -10,7 +10,7 @@ import SwiftUI
|
||||
|
||||
struct RepositoryListView : View {
|
||||
|
||||
@ObjectBinding
|
||||
@ObservedObject
|
||||
private(set) var viewModel: RepositoryListViewModel
|
||||
|
||||
var body: some View {
|
||||
@@ -24,15 +24,15 @@ struct RepositoryListView : View {
|
||||
onCommit: { self.viewModel.search() })
|
||||
.frame(height: 40)
|
||||
.padding(EdgeInsets(top: 0, leading: 8, bottom: 0, trailing: 8))
|
||||
.border(Color.gray, cornerRadius: 8)
|
||||
.padding(EdgeInsets(top: 0, leading: 16, bottom: 0, trailing: 16))
|
||||
.background(RoundedRectangle(cornerRadius: 8).strokeBorder(Color.gray, lineWidth: 2))
|
||||
|
||||
Button(action: { self.viewModel.search() }) {
|
||||
Text("Search")
|
||||
}
|
||||
.frame(height: 40)
|
||||
.padding(EdgeInsets(top: 0, leading: 8, bottom: 0, trailing: 8))
|
||||
.border(Color.blue, cornerRadius: 8)
|
||||
.background(RoundedRectangle(cornerRadius: 8).strokeBorder(Color.blue, lineWidth: 2))
|
||||
.padding(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 16))
|
||||
}
|
||||
|
||||
|
||||
@@ -10,10 +10,10 @@ import Combine
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
final class RepositoryListViewModel: BindableObject {
|
||||
final class RepositoryListViewModel: ObservableObject {
|
||||
typealias SearchRepositories = (String) -> AnyPublisher<Result<[Repository], ErrorResponse>, Never>
|
||||
|
||||
let willChange: AnyPublisher<RepositoryListViewModel, Never>
|
||||
let objectWillChange: AnyPublisher<RepositoryListViewModel, Never>
|
||||
private let _didChange = PassthroughSubject<RepositoryListViewModel, Never>()
|
||||
|
||||
private let _searchWithQuery = PassthroughSubject<String, Never>()
|
||||
@@ -34,7 +34,7 @@ final class RepositoryListViewModel: BindableObject {
|
||||
init<S: Scheduler>(searchRepositories: @escaping SearchRepositories = RepositoryAPI.search,
|
||||
mainScheduler: S) {
|
||||
|
||||
self.willChange = _didChange.eraseToAnyPublisher()
|
||||
self.objectWillChange = _didChange.eraseToAnyPublisher()
|
||||
|
||||
let response = _searchWithQuery
|
||||
.filter { !$0.isEmpty }
|
||||
|
||||
Reference in New Issue
Block a user