Created
March 8, 2017 12:27
-
-
Save vojto/60bff53eb21704d6899cc5cc2a303e2c to your computer and use it in GitHub Desktop.
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
| // Pick | |
| public extension SignalProducer where Value: OptionalProtocol { | |
| func pick<T>(picking: @escaping ((Value.Wrapped) -> (SignalProducer<T?, Error>))) -> SignalProducer<T?, Error> { | |
| return self.flatMap(.latest) { value -> SignalProducer<T?, Error> in | |
| if let value = value.optional { | |
| return picking(value) | |
| } else { | |
| return SignalProducer<T?, Error>(value: nil) | |
| } | |
| } | |
| } | |
| } | |
| // Usage | |
| class LayerTableCellView: NSTableCellView { | |
| // Views | |
| @IBOutlet var label: NKLabel! | |
| // Models | |
| internal let config = MutableProperty<ChartConfigModel?>(nil) | |
| override func awakeFromNib() { | |
| let title = config.producer.pick { $0.reactive.title.producer } | |
| label.reactive.text <~ title.map { $0 ?? "" } | |
| } | |
| func setConfig(_ config: ChartConfigModel) { | |
| self.config.value = config | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment