https://kotlinlang.org logo
#coroutines
Title
# coroutines
c

Christopher Elías

05/31/2021, 8:43 PM
Hi guys, I'm stuck on this for weeks. I'm trying to recreate this but using Flows instead of RxJava.
Copy code
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
fun <T : Any, U : Any> Observable<T>.notOfType(clazz: Class<U>): Observable<T> {
  checkNotNull(clazz) { "clazz is null" }
  return filter { !clazz.isInstance(it) }
}

/**
 * take only the first ever InitialIntent and all intents of other types
 * to avoid reloading data on config changes
 */
private val intentFilter: ObservableTransformer<TasksIntent, TasksIntent>
  get() = ObservableTransformer { intents ->
    intents.publish { shared ->
      Observable.merge(
        shared.ofType(TasksIntent.InitialIntent::class.java).take(1),
        shared.notOfType(TasksIntent.InitialIntent::class.java)
      )
    }
  }
Is for avoid fire the InitialIntent twice (MVI pattern) can someone know how can I accomplish this? My current implementation of it kinda sucks https://github.com/ChristopherME/counter-android-mvi/blob/685756dca1a6f0e89627cb0e[…]myapplication/presentation/features/counter/CounterViewModel.kt
🆘 1
j

julian

05/31/2021, 9:23 PM
Just curious, how come you're using
Channel
for
actions
instead of
MutableStateFlow
?
c

Christopher Elías

05/31/2021, 9:27 PM
Hi Julian, well I'm actually experimenting with all right now, in order to replicate the inspiration project. I'm using a channel because I thought It will be the best option for handle multiple intents (the app has a button that can be triggered multiple times) at the same time. Also, I receive it as a Flow inside the viewModelScope. And I think that StateFlow is designed for "State" implementations. But as I said, I'm experimenting with flows, kinda noobie.
👍 1
3 Views