我正在使用
Flowable.combineLatest(query,params)
用于监听查询变化和一些参数变化
但现在我想引入分页并监听偏移量变化,但这里的问题是当查询发生变化时我需要重置偏移量。
想知道如何使用 RxAndroid 实现它?
基本上我们观察到 3 个或更多对象(查询、偏移量、connectionChange)
我想要实现的是监听任何 observables 的变化 + 当查询改变时更新偏移值
最佳答案
要查看值的来源,您必须以某种方式标记值,这需要对每个源进行转换。例如:
data class Tuple<T>(val value: T, val index: Long) { ... }
Flowable.defer {
var indices: Array<Long>(4) { 0 }
var latests: Array<Long>(4) { 0 }
Flowable.combineLatest(
source1.map { Tuple(it, indices[0]++) },
source2.map { Tuple(it, indices[1]++) },
source3.map { Tuple(it, indices[2]++) },
source4.map { Tuple(it, indices[3]++) },
{ tuple1, tuple2, tuple3, tuple4 ->
if (tuple1.index != latests[0]) {
// first source changed
}
if (tuple2.index != latests[1]) {
// second source changed
}
if (tuple3.index != latests[2]) {
// third source changed
}
if (tuple4.index != latests[3]) {
// fourth source changed
}
latests[0] = tuple1.index
latests[1] = tuple2.index
latests[2] = tuple3.index
latests[3] = tuple4.index
}
)
}
关于android - 我怎么知道在 RxAndroid 的 combineLatest 中哪个 observable 发生了变化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65172763/