-
Notifications
You must be signed in to change notification settings - Fork 6
Flow
Flow is a class that applies the observer pattern. It exposes subscribe
and unsubscribe
method.
Kaskade has an extension to subscribe to states using Flow
instead of using the onStateChanged
function.
fun <A : Action, S : State> Kaskade<A, S>.stateFlow(): Flow<S>
There's a subclass of Flow
called DamFlow
. The name comes from the concept of dam that is a barrier that prevents water from flowing.
DamFlow
saves values emitted by type. In subscribing states, every type that it is emitted is saved in the dam. It saves every latest emission by type except for SingleEvent
. SingleEvents are not saved into the Dam.
sealed class SampleState : State {
data class Screen(
val items: List<String>,
val errorMessage: String,
val isLoading: Boolean
) : SampleState()
data class Error(val message: String) : SampleState(), SingleEvent
}
Error
state being a SingleEvent
does not get saved to the Dam and is only emitted by the Flow
.
Saved values in a DamFlow
are emitted when the flow is subscribed again.
For more information see LiveData section