Please enable JavaScript.
Coggle requires JavaScript to display documents.
JETPACK COMPOSE - Coggle Diagram
JETPACK COMPOSE
MUTABLE STATE FLOW vs MUTABLE/COMPOSE STATE
When to use each
A one-shot API in Jetpack Compose is a function that performs a single Create, Read, Update, or Delete (CRUD) operation
COMPOSE STATE
working with TextField composables
Use Case: This approach is best suited for a simple state that is local to individual composables or when the state does not need to be shared across different layers of the application.
THREADING
Updates must be made on the main thread, requiring careful threading management when interacting with background tasks.
A lackof built-in concurrency support can complicate its use in more complex or multi-threaded environments. :warning:
LIFECYCLE
Tightly coupled with the Compose runtime, which automatically handles lifecycle events within the UI.
Does not inherently support streaming multiple values over time unless explicitly managed within composables.
REF
https://proandroiddev.com/mutablestate-or-mutablestateflow-a-perspective-on-what-to-use-in-jetpack-compose-ccec0af7abbf#:~:text=While%20MutableState%20works%20well%20within,the%20same%20underlying%20MutableState%20instance
. :star:
MUTABLE STATE FLOW
Use Case: This is ideal for states that are observed or shared across multiple components or layers of the application, such as in business logic or data handling.
THREADING
Inherently thread-safe and can safely handle updates from any thread.
Supports concurrent operations and can be combined with other flows, making it highly effective for reactive programming across different parts of an application.
USE collectAsStateWithLifecycle
:star:
onFollowClick = viewModel::followAuthorToggle,
USE FUNCTIONS REF TO PASS DATA DOWN TO STREAM
COURSES