在RxKotlin / RxJava中用BehaviorSubject自动创建热可观察对象
目前我正在使用RxKotlin在Kotlin上建立一个项目。 我与Rx的背景主要是基于RxJS。
我经常用于在Typescript中创建hot observables
模式的模式看起来是这样的:
private dataStore: IFoo; private dataStoreSubject: BehaviorSubject = new BehaviorSubject(this.dataStore); public dataStoreObservable: Observable = Observable.from(this.dataStoreSubject); public getNetworkData(): Observable { return this.http.get() .map((response: IResponse) => { this.dataStore = response; this.dataStoreSubject.next(this.dataStore); return this.dataStore; }); }
这将允许我暴露一个Observable
,而不暴露Subject
和后续的subject.next();
方法。
我的问题是:在RxKotlin或RxJava中建立类似逻辑最常用的方法是什么?