Hot Flow π₯
β‘οΈ A hot flow is a data flow that emits values regardless of whether there are active collectors. It can produce values even if there are no subscribers.
β‘οΈ New collectors joining a hot flow might miss emissions that occurred before they started listening.
β‘οΈ If we subscribe to a hot flow, we will start receiving emissions from the point where the flow is currently at. If the flow has already completed emitting values, we will not receive any emissions.
β When to use?
β‘οΈ Hot flows are typically used for tasks that need to be performed continuously, such as updating a Ul with real-time data.
β Example
StateFlow and SharedFlow
β‘οΈ A hot flow is a data flow that emits values regardless of whether there are active collectors. It can produce values even if there are no subscribers.
β‘οΈ New collectors joining a hot flow might miss emissions that occurred before they started listening.
β‘οΈ If we subscribe to a hot flow, we will start receiving emissions from the point where the flow is currently at. If the flow has already completed emitting values, we will not receive any emissions.
β When to use?
β‘οΈ Hot flows are typically used for tasks that need to be performed continuously, such as updating a Ul with real-time data.
β Example
StateFlow and SharedFlow
How to observe lifecycle events (onCreate(), onResume(), onStart(),
etc)
Owner CompositionLocal can provide the current LifecycleOwner.
etc)
Owner CompositionLocal can provide the current LifecycleOwner.
You can use SubComposeLayout to measure and resize Composables.
Here we have a username field and a button that enables when the username is valid.
It starts off empty and so our state is false. Now when the user starts typing, our state correctly updates and our button becomes enabled.
This is where derivedStateOf comes in. Our state is changing more than we need our UI to update and so derivedStateOf can be used for this to reduce the number of recompositions.
It acts similarly to the Kotlin Flows distinctUntilChanged() operator.
It starts off empty and so our state is false. Now when the user starts typing, our state correctly updates and our button becomes enabled.
This is where derivedStateOf comes in. Our state is changing more than we need our UI to update and so derivedStateOf can be used for this to reduce the number of recompositions.
It acts similarly to the Kotlin Flows distinctUntilChanged() operator.