flatMap内的CombineLatest

时间:2018-10-12 07:04:14

标签: rx-java2 combinelatest

我的设置类似于以下内容(用于解释问题的抽象示例):

val o1: Observable<List<Parent>> = ... // simply parent observable without dependencies
val o2: Observable<List<Child>> = ... // simply child observable without dependencies

val o3: Observable<List<Child>> = o2.flatMapSingle {
    Observable.fromIterable(it)
        .flatMapSingle { getChildrenOfChild(it) } // <= simply get all children of the child `it`
        .toList()
    }

// Observable with the data of ALL parents and children
val o = Observable.combineLatest(o1, o3, BiFunction<List<Parent>, List<Child>, Pair<List<Parent>, List<Child>> {
    parents, children -> Pair(parents, children) })
    .map {
        // here the data is converted to my desired UI state
    }

只要父母列表或子列表发生变化,它就会发出新数据。我想对此进行调整,以便每当孩子的孩子列表发生变化时,孩子列表就会发出新的项目,我能以某种方式做到这一点吗?我不知道如何在内部combineLatest中使用类似flatMap的东西...

我想要的

  • [DONE]只要父母列表或孩子列表发生变化,就会创建新的UI状态
  • [NOT DONE]每当孩子的孩子发生变化时,我要发出一个新的孩子列表(这会自动导致孩子列表发生变化,因此会生成新的UI状态)

有什么办法解决这个问题吗?

0 个答案:

没有答案
相关问题