Skip to content

Commit 416f013

Browse files
committed
mark: rx - Reactive - Binder
1 parent eb92c2e commit 416f013

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

Swift_Play/Module/RxSwift/RxSwiftViewController.swift

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,9 +465,36 @@ extension RxSwiftViewController{
465465

466466
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
467467
Observable.just("Hello Binder")
468-
.bind(to: self.contentLabel.rx.text) // self.contentLabel.rx.text是RX内置的Binder , 这版RxSwift可能调整了,和中文文档解释的不一样
468+
.bind(to: self.contentLabel.rx.text)
469469
}
470470

471+
/**
472+
self.contentLabel.rx实际返回了Reactive(self)
473+
Reactive实现了 @dynamicMemberLookup,通过keyPath获取到
474+
Binder(self.base) { base, value in base[keyPath: keyPath] = value} 这个Binder
475+
476+
@dynamicMemberLookup
477+
public struct Reactive<Base> {
478+
/// Base object to extend.
479+
public let base: Base
480+
481+
/// Creates extensions with base object.
482+
///
483+
/// - parameter base: Base object.
484+
public init(_ base: Base) {
485+
self.base = base
486+
}
487+
488+
/// Automatically synthesized binder for a key path between the reactive
489+
/// base and one of its properties
490+
public subscript<Property>(dynamicMember keyPath: ReferenceWritableKeyPath<Base, Property>) -> Binder<Property> where Base: AnyObject {
491+
Binder(self.base) { base, value in
492+
base[keyPath: keyPath] = value
493+
}
494+
}
495+
}
496+
497+
*/
471498

472499
// self.startBtn.rx.isEnabled
473500
}

0 commit comments

Comments
 (0)