RxSwift源码札记-4:Subject多种类型

203 阅读1分钟

ReplaySubject

每个通知广播给全部的以前的的和将来的观察者 ,受制于缓冲区策略

Represents an object that is both an observable sequence as well as an observer.

Each notification is broadcasted to all subscribed and future observers, subject to buffer trimming policies.

BehaviorSubject

Represents a value that changes over time.Observers can subscribe to the subject to receive the last (or initial) value and all subsequent notifications.

表示随时间变化的值。观察者可以订阅主题获取最后一个(或者初始化)的值和后续的全部通知

PublishSubject

表示一个对象,它既是可观察序列也是观察者

每个通知广播给全部已经订阅的观察者

Represents an object that is both an observable sequence as well as an observer.

Each notification is broadcasted to all subscribed observers.

AsyncSubject

 AsyncSubject发射源序列发射的最后一个值(只发射最后一个值),并且只在源序列completes之后(如果源序列没有发射任何值,无需发射任何值AsyncSubject也能完成)

An AsyncSubject emits the last value (and only the last value) emitted by the source Observable,

and only after that source Observable completes. (If the source Observable does not emit any values, the AsyncSubject also completes without emitting any values.)