Hi guys, I'm stuck on this for weeks. I'm trying t...
# coroutines
c
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
Just curious, how come you're using
Channel
for
actions
instead of
MutableStateFlow
?
c
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