Data Flow
The diagram illustrates a typical code flow for a feature-based architecture in a Kotlin Multiplatform Mobile (KMM) application.He
Last updated
The diagram illustrates a typical code flow for a feature-based architecture in a Kotlin Multiplatform Mobile (KMM) application.He
Last updated
Let's get an overview of the basic data structures used in the system and how they are consumed by predefined automated views to streamline data flow and handle common view states.
RemoteData<T>
which is an alias of Option<Either<ErrMessage, T>>
: Represents a single piece of data, including its loading state and potential errors.
RemoteDataPaginated<T>
an alias of Option<Either<ErrMessage, Page>>
: Represents a paginated list of data, including information about the current page, total pages, and the data itself.
RemoteListData<T>
alias of Option<Either<ErrMessage, List>>
: Represents a simple list of data.
Key Components:
Option
: A type from ArrowKT that represents an optional value, which can be Some
(present) or None
(absent).
Either
: Another type from ArrowKT that represents a value that can be either a Right
(success) or a Left
(error).
Purpose of Option
and Either
:
Option
: Used to represent the initial loading state (none) and potential errors (left).
Either
: Used to represent the success or error outcomes of data fetching.
Data Fetching: The repository fetches data from the server using HTTP requests.
Data Processing: The repository processes the fetched data, transforming it into one of the three data structures.
Data Propagation: The data structure is propagated through the view model to the view.
View Rendering: The view automatically handles the loading state, error display, and data rendering based on the data structure.
RemoteData<T>
:
Kotlin
Use code with caution.
RemoteDataPaginated<T>
:
Kotlin
Use code with caution.
RemoteListData<T>
:
Kotlin
Use code with caution.
Simplified View Logic: Predefined views automatically handle loading states and errors, reducing boilerplate code.
Consistent Error Handling: The Either
type provides a consistent way to handle errors.
Flexibility: These data structures can be used to represent various types of data.
Improved Readability: The Option
type makes the code more expressive and easier to understand.
By understanding these data structures and their usage, you can effectively manage data flow and improve the user experience in your KMM applications.