简体   繁体   English

一个Observable对另一个RxJava2的依赖

[英]Dependence of one Observable on another RxJava2

There is a class, it has observable fields. 有一个类,它具有可观察的字段。 I want to update localData 我想更新localData

when receiving remote data remoteData , for some reason I can not get data in localData , debugging does not go to a breakpoint even to getIdsInDatumsRemote () . 当接收远程数据remoteData ,由于某种原因我无法在localData获取数据,因此localData调试getIdsInDatumsRemote ()也不会转到断点。 The identifyDatumsForUpdate () method gets an empty Observable. identifyDatumsForUpdate ()方法获取一个空的Observable。

class DiskDatumDataStore {

    var remoteData: Observable<Data>? = null

    var localData: Observable<Data>? = null

    override fun sync() {
        remoteDatums = getChangedRemoteData(lastUpdated!!, 1000)!!
        localDatums = remoteDatums!!.map {
            getIdsInDatumsRemote(it)
        }.map {
            it.map {
                it.toLong()
            }
        }.flatMap {
            getOldLocalData(it)
        }


        identifyDatumsForUpdate(datumsForUpdateLocal, datumsForUpdateRemote)
    }

    override fun getOldLocalData(remoteDatumsIds: List<Long>): Observable<List<DataLayerTypesOfResponsibility>> {
        return Observable.fromCallable { repository.getOldDatum(remoteDatumsIds) }      
    }
}

You're not subscribing to your Observable . 您没有subscribing Observable You're just creating it. 您只是在创建它。

localDatums = remoteDatums!!.map {
            getIdsInDatumsRemote(it)
        }.map {
            it.map {
                it.toLong()
            }
        }.flatMap {
            getOldLocalData(it)
        }.subscribe { it->
            //do something with the result `it`
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM