Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
func setupObserving() {
currentWeatherView.reactive.weatherFeatures <~ viewModel.weatherFeatures
loadingIndicator.reactive.isAnimating <~ viewModel.isLoading
segmentedControl.reactive.isEnabled <~ viewModel.isEnabledControl(for: Set([.turnCurrent, .turnForecast]))
reactive.title <~ viewModel.title
reactive.rightBarButtonItem <~ viewModel.isLoading.map { [weak self] (isLoading) -> UIBarButtonItem? in
return isLoading ? self?.loadingBarButtonItem : self?.refreshBarButtonItem
}
leftBarButtonItem.reactive.pressed = CocoaAction(viewModel.createButtonAction(for: .turnLeft))
rightBarButtonItem.reactive.pressed = CocoaAction(viewModel.createButtonAction(for: .turnRight))
refreshBarButtonItem.reactive.pressed = CocoaAction(viewModel.reloadAction)
locateBarButtonItem.reactive.pressed = CocoaAction(viewModel.locateAction)
let action = viewModel.uiAction
segmentedControl.reactive.controlEvents(.valueChanged)
.map { $0.selectedSegmentIndex == 0 ? UIEvent.turnCurrent : UIEvent.turnForecast }
.observeValues { action.apply($0).start() }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.