daniaviladomingo / kmm

Rick & Morty Kotlin/Compose Multiplatform: Ktor, Sqldelight, Koin, Flow, MVI, Compose
178 stars 15 forks source link

what is the difference? #4

Open periva101 opened 2 years ago

periva101 commented 2 years ago

Hello again, I almost study each GitHub KMM sample your's is the best. I have a question if you plz.

  private val _event: MutableSharedFlow<Event> = MutableSharedFlow()
    val event = _event.asSharedFlow()

    private val _effect: Channel<Effect> = Channel()
    val effect = _effect.receiveAsFlow()

what is the clear difference between effects and events? and why events are MutableSharedFlow where _effect is Channel

daniaviladomingo commented 2 years ago

Hi!

Thank you so much!!

Event are UI action to ViewModel. UI -> ViewModel Effect are single shot event from ViewModel to UI (don't have state) like show toast, show snack bar, show dialog or navigation action.

MVI pattern is based in this great article: https://proandroiddev.com/mvi-architecture-with-kotlin-flows-and-channels-d36820b2028d

ghost commented 2 years ago

Thank you so much! Thank you so much!! Thank you so much!!!