Skip to content

Instantly share code, notes, and snippets.

@pimnijman
Created October 7, 2019 12:28
Show Gist options
  • Save pimnijman/bb45172116576c767da3c6a405ca5eaf to your computer and use it in GitHub Desktop.
Save pimnijman/bb45172116576c767da3c6a405ca5eaf to your computer and use it in GitHub Desktop.
ReactiveExtension to create a bidirectional binding with a CosmosView rating control
//
// ReactiveExtensionsCosmos.swift
// Route.nl
//
// Created by Pim Nijman on 07/09/2019.
// Copyright © 2019 Falk. All rights reserved.
//
import Bond
import ReactiveKit
import Cosmos // https://github.com/evgenyneu/Cosmos
extension ReactiveExtensions where Base: CosmosView {
public var rating: DynamicSubject<Double> {
return dynamicSubject(
signal: didTouchCosmosSignal,
get: { $0.rating },
set: { $0.rating = $1 }
)
}
public var didTouchCosmosSignal: SafeSignal<Void> {
let base = self.base
return Signal { [weak base] observer in
guard let base = base else {
observer.completed()
return NonDisposable.instance
}
base.didTouchCosmos = { _ in
observer.next(())
}
return BlockDisposable {
base.didTouchCosmos = nil
}
}.take(until: base.deallocated)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment