Last active
August 21, 2018 15:39
-
-
Save aabanaag/077ef3593fbbe132ee762a1bf960b10d to your computer and use it in GitHub Desktop.
Updated Event
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EventViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
bindable() | |
} | |
private func bindable() { | |
searchbar.rx.text | |
.orEmpty | |
.distinctUntilChanged() | |
.throttle(0.5, scheduler: MainScheduler.instance) | |
.subscribe(onNext: { [unowned self] criteria in | |
self.viewModel.getEvents(criteria: criteria) | |
}) | |
.disposed(by: bag) | |
viewModel.events | |
.asDriver(onErrorJustReturn: []) | |
.map { [EventSection(name: "", items: $0)] } | |
.drive(table.rx.items(dataSource: dataSource)) | |
.disposed(by: bag) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct EventViewModel { | |
private let service = EventService() | |
private let _events = BehaviorRelay<[Event]>(value: []) | |
private let bag = DisposeBag() | |
var organizationId: Int! | |
var user: User! | |
var events: Driver<[Event]> { return _events.asDriver() } | |
var isTableLoading: BehaviorRelay<Bool>! | |
var criteria: BehaviorRelay<String>! | |
var tickets: Observable<[Ticket]>! | |
var badges: Observable<[Badge]>! | |
init(_ user: User) { | |
self.user = user | |
self.organizationId = user.organization | |
self.isTableLoading = BehaviorRelay<Bool>(value: false) | |
} | |
func getEvents(criteria: String) { | |
let parameters: [String: Any] = [ | |
"search": criteria, | |
"organization": organizationId | |
] | |
service.getEvents(parameters: parameters) | |
.bind(to: _events) | |
.disposed(by: bag) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment