RxSwift - kirseia/study GitHub Wiki
-
Subjects ๋ Observer / Observable ๋ ์ญํ ์ ๋ชจ๋ ์ํํ๋ ๋ธ๋ฆฟ์ง ๋๋ ํ๋ก์
-
ํ๋์ ์ด์์ Observable ์ ๊ตฌ๋ ํ๊ณ ๊ฐ์ ๋ด๋ณด๋ด๋ฆฌ๊ณ ํจ
-
PublishSubject - ๊ตฌ๋ ์ดํ์๋ง ๊ฐ์ ์ ๋ฌ
-
ReplaySubject - ๋ฒํผ ํฌ๊ธฐ ๋งํผ์ ๊ฐ์ ์ ์ฅํ๊ณ ์์ ์ ์์
-
BehaviorSubject - ํ๋์ ๋ฒํผ๋ฅผ ๊ฐ์ง๋ Subject, ๊ตฌ๋ ํ ๋ง์ง๋ง ๊ฐ์ ์ ๋ฌ
-
Variable - BehaviorSubject๋ฅผ ๊ฐ์์ผ๋ฉฐ complete๋ error๊ฐ ๋ฐ์ํ์ง ์์, ํด์ ๋ ๋ complete ๋ฐ์
- Variable์ ์์ด์ง๊ณ BehaviorRelay ๋ก ๋์ฒด๋จ
- UI์์ ์ฌ์ฉํ๊ธฐ ์ํด Subject๋ฅผ Relay ๋ก ๋ง๋ ๊ฒ์ฒ๋ผ (error ์๋๋), Observable์ด ์๋ฌ๋ฅผ ๋ฌด์ํ๋ ค๋ฉด Driver / Signal๋ก ์จ์ผ ํจ
- ๊ธฐ๋ณธ์ด main thread ์ด Observable
- signal ์ subscribe ์ดํ์ (like publishSubject), driver ๋ subscribe ์์ ์ ์ด์ ๊ฐ๋ (like behaviorSubject)
- Observable -> bind to -> binder
- binder๋ obervable value ์ ๋ฐ์ํจ.
extension Reactive where Base: UIViewController {
/// Bindable sink for `startAnimating()`, `stopAnimating()` methods.
public var isAnimating: Binder<Bool> {
return Binder(self.base, binding: { (vc, active) in
if active {
vc.startAnimating()
} else {
vc.stopAnimating()
}
})
}
}