// // CheckBox+Rx.swift // GME Remit // // Created by InKwon James Kim on 2020/01/02. // Copyright © 2020 Gobal Money Express Co. Ltd. All rights reserved. // import RxSwift import RxCocoa extension Reactive where Base: CheckBox { fileprivate var delegate : RxCheckBoxDelegateProxy { return RxCheckBoxDelegateProxy.proxy(for: base) } var isSelected : Observable { return delegate.isSelected.asObservable() } } // MARK: RxCheckBoxDelegateProxy class RxCheckBoxDelegateProxy: DelegateProxy, DelegateProxyType, CheckBoxDelegate { internal var isSelected = BehaviorSubject(value: false) init(parentObject: CheckBox) { super.init(parentObject: parentObject, delegateProxy: RxCheckBoxDelegateProxy.self) } public static func registerKnownImplementations() { self.register { RxCheckBoxDelegateProxy(parentObject: $0) } } func checkBox(_ checkBox: CheckBox, isSelected: Bool) { self.isSelected.onNext(isSelected) self.forwardToDelegate()?.checkBox(checkBox, isSelected: isSelected) } static func currentDelegate(for object: CheckBox) -> CheckBoxDelegate? { return object.delegate } static func setCurrentDelegate(_ delegate: CheckBoxDelegate?, to object: CheckBox) { object.delegate = delegate } deinit { isSelected.onCompleted() } }