目前我正在使用 RxKotlin 在 Kotlin 中构建一个项目。我的 Rx 背景主要基于 RxJS。
我经常用于在 Typescript 中创建热可观察对象
的模式看起来类似于:
private dataStore: IFoo;
private dataStoreSubject: BehaviorSubject<IFoo> = new BehaviorSubject(this.dataStore);
public dataStoreObservable: Observable<IFoo> = Observable.from(this.dataStoreSubject);
public getNetworkData(): Observable<IFoo[]> {
return this.http.get()
.map((response: IResponse) => {
this.dataStore = <IFoo[]>response;
this.dataStoreSubject.next(this.dataStore);
return this.dataStore;
});
}
这将允许我公开一个 Observable
,而不公开 Subject
以及随后的 subject.next();
方法。
我的问题是:在 RxKotlin 或 RxJava 中建立类似逻辑的最惯用方法是什么?
最佳答案
您需要使用组合和转换。您可以将主题和可观察对象之间的“链接”添加到转换中。
关于java - 在 RxKotlin/RxJava 中使用 BehaviourSubject 惯用地创建热可观察对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48568178/