Skip to content

Instantly share code, notes, and snippets.

@soxjke
Created December 3, 2017 16:20
Show Gist options
  • Save soxjke/4c4a7fb80e793958268b7c258eed6f80 to your computer and use it in GitHub Desktop.
Save soxjke/4c4a7fb80e793958268b7c258eed6f80 to your computer and use it in GitHub Desktop.
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