RXSwift 原理图
2021-10-26 10:14:55 0 举报
RXSwift原理图
作者其他创作
大纲/内容
ObserverOn<Element>
let subscribeHandler: SubscribeHandler
传递 Event<Element>
Observable<ob.Element>
Producer<SourceType>
1. subscribeOn
private let state = AtomicInt(0) private var sink: Disposable? private var subscription: Disposable?
3. observer.on(event:)
6. run 创建SubscribeOnSink
Observer<Element>
subscribeHandler(AnyObserver(Sink))
fileprivate let observer: Observerfileprivate let cancel: Cancelable
Observable<SourceType>
Sink<Observer: ObserverType>
Observer
Sink
SubscribeOn<Ob: ObservableType>
subscribe
9. observer.on(event<Element>)
Observable
sink 即 AnonymousObservableSink,维护Observer 和 Obserable 之间的订阅状态subscription 即 subscribeHandler 执行返回的值,维护 subscribeHandler 执行中一些状态SinkDisposer 即用来维护 Observable , Observer 以及 它们之间的订阅关系状态
AnonymousObservable<Element>
Observable<Element>
3. subscribe
SinkDisposer
ObserveOnSink<Observer: ObserverType>
Observable<ResultType>
7. disaptch_asyn{subcribe}
AnonymousObservableSink<Observer: ObserverType> : ObserverType
observer.on(event<SourceType>)
AnonymousObservable<SourceType>
2. Produce.run()subscribeHandler(AnyObserver(Sink))
let scheduler: ImmediateSchedulerType let source: Observable<Element>
Obserable Create
Disposable
11. dispatch_asyncobserver.on(event<Element>)
10. observer.on(event<Element>)
Producer<ob.Element>
Map 操作
Cancelable
Producer<.Element>
AnonymousObservableSink
let source: Ob let scheduler: ImmediateSchedulerType
8. run subscribeHandler(AnyObserver(Sink))
1. 订阅关系 subscribe
2. observerOn
Scheduler
observer.on(event<ResultType>)
4. run 创建ObservableOnSink
订阅关系 subscribe
创建 MapSink, 建立MapSink 与 上一节 sink的关联
5. subscribe
Operator Map
Producer<ResultType>
let source: Observable<SourceType>let transform: Transform
MapSink
Producer<Element>
创建了新的Observable 即 Map
收藏
收藏
0 条评论
下一页