【问题标题】:Is there, in kotlin and android, something similar to switchmap in rxjs or rxjava?在 kotlin 和 android 中是否有类似于 rxjs 或 rxjava 中的 switchmap 的东西?
【发布时间】:2019-10-20 16:50:10
【问题描述】:

我想知道在 kotlin 和 android 中是否有类似于 switchmap 的东西(可能是 LiveData)。

我需要在事件发生后立即更改我的请求,这些事件分别决定了从服务器请求什么,我只需要最后一个请求

【问题讨论】:

    标签: android kotlin android-livedata kotlin-coroutines switchmap


    【解决方案1】:

    在 Kotlin 中,您可以按如下方式使用转换库

    val someLiveData: LiveData<Type> = ...
    
    val someOtherValue = Transformations.switchMap(someLiveData) { changedValue: Type ->
        //Assign someOtherValue using changedValue, the value coming from someLiveData.
    }
    

    【讨论】:

      猜你喜欢
      • 2021-09-29
      • 2017-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多