Let’s build your first Store.
commonMain
code.Add the Dependency
commonMain
source set.libs.versions.toml
file is part of Gradle’s Version Catalogs feature, which simplifies dependency management.If you’re not using Version Catalogs, you can add the dependency directly to your build.gradle.kts
:Sync the Project
Define the Data Models
PostEntity
class might look after generation:Create the API Interface
@Inject
annotation indicates a class can be injected.Implement Converters
Set Up the Store Factory
PostStore
instance.TODO()
Placeholders:The TODO()
placeholders indicate where implementations will be provided in the subsequent steps.Implement the Fetcher
PostOperations
interface.Implement the Source of Truth
SourceOfTruth
observes changes in the database, use asFlow()
and appropriate mapping functions.Implement the Converter
PostExtensions
object.Implement the Updater
Implement the Bookkeeper
Build the Store
Fetcher
: Retrieves data from the network.Source of Truth
: Manages local data storage.Converter
: Handles data transformations between models.Updater
: Syncs local changes back to the network.Bookkeeper
: Keeps track of failed updates for retry mechanisms.Create a Post Repository
PostRepository
that uses the PostStore
to fetch and cache post data. The primary reason for this extra layer is it enables us to extract Store
from the domain layer as an implementation detail of the PostRepository
. It also enables us to add additional methods and strategies to the PostRepository
in the future.PostRepository
is feature agnostic. We define the PostRepository
under the
common lib/market/post/api
namespace and implement it in the
lib/market/post/impl
module to facilitate its reuse across features.
Consumers can depend on the lib/market/post/api
module without being exposed
to the implementation details, such as the PostStore
.Implement the Post Detail Presenter
PostDetailScreenPresenter
will use the PostRepository
to load the post data and update the UI in response to user actions.Display the Post Detail Screen