Created
December 3, 2017 16:20
-
-
Save soxjke/4c4a7fb80e793958268b7c258eed6f80 to your computer and use it in GitHub Desktop.
This file contains 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
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