Skip to content

Instantly share code, notes, and snippets.

View vaderdan's full-sized avatar
🏠
Working from home

Dani Lazarov vaderdan

🏠
Working from home
View GitHub Profile
let textFull = BehaviorRelay<String?>(value: nil)
let textFirst = BehaviorRelay<String?>(value: nil)
let textSecond = BehaviorRelay<String?>(value: nil)
typealias ItemType = (current: String, previous: String)
Observable.combineLatest(textFirst.map({ $0 ?? "" }).currentAndPrevious(), textSecond.map({ $0 ?? "" }).currentAndPrevious(), textFull.map({ $0 ?? "" }).currentAndPrevious())
.filter({ (first: ItemType, second: ItemType, full: ItemType) -> Bool in
return "\(first.current) \(second.current)" != full.current && "\(first.current)" != full.current
let textFirst = BehaviorRelay<String?>(value: nil)
let textSecond = BehaviorRelay<String?>(value: nil)
(textSecond <-> textFirst).disposed(by: disposeBag)
let bindToRelay = property
.subscribe(onNext: { n in
relay.accept(n)
}, onCompleted: {
bindToUIDisposable.dispose()
})
let bindToUIDisposable = relay.bind(to: property)
// Two way binding operator between control property and relay, that's all it takes.
infix operator <-> : DefaultPrecedence
func <-> <T>(property: ControlProperty<T>, relay: BehaviorRelay<T>) -> Disposable {
let bindToUIDisposable = relay.bind(to: property)
let bindToRelay = property
.subscribe(onNext: { n in
relay.accept(n)
}, onCompleted: {
bindToUIDisposable.dispose()
import RxBiBinding
let disposeBag = DisposeBag()
var textFieldFirst = UITextField()
var textFieldSecond = UITextField()
(textFieldFirst.rx.text <-> textFieldSecond.rx.text).disposed(by: disposeBag)
@vaderdan
vaderdan / MenuViewCellModel.swift
Last active November 19, 2018 18:04
Sourcery Model protocols generating
class MenuViewCellModel: AutoModel {
/// sourcery:begin: input
var detailsAction: Action<Observable<Menu>, Void> = {
return Action<Observable<Menu>, Void> { _ in
return .empty()
}
}()
/// sourcery:end
@vaderdan
vaderdan / 0_reuse_code.js
Created April 17, 2016 07:56
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console