Introduction to Store5
Store5 is a powerful library that provides a robust solution for handling data from local and network sources in mobile applications. Developed under the Mobile Native Foundation, Store5 offers an intuitive and efficient system for managing data flow, ensuring a seamless experience for developers.
Key Concepts
At its core, Store5 is a typed repository that handles a variety of data states including Data, Loading, and Error, enabling developers to work efficiently with both local and network data sources. Here are some of the fundamental components of Store5:
-
Store: This component provides a flow of data that developers can tap into, allowing them to handle real-time updates and synchronize data between local storage and network sources.
-
MutableStore: An extension of the Store component, MutableStore allows developers to perform CRUD (Create, Read, Update, and Delete) operations on resources. This makes it ideal for applications that require dynamic data handling.
-
SourceOfTruth: This serves as the backbone of data persistence within Store5. It ensures that local copies of data are stored reliably, acting as a single source of truth for the application.
-
Fetcher: This is responsible for defining how data is retrieved over the network. It provides a mechanism to specify the access patterns to remote data sources.
-
Updater: An essential component for pushing local changes to a network, ensuring data consistency and integrity across different platforms.
-
Bookkeeper: This component tracks metadata of local changes, and logs any synchronization failures, enabling easier diagnostics and data management.
-
Validator: This ensures the integrity of data by determining whether an item is valid, helping to maintain high data quality within applications.
-
Converter: Facilitates the conversion of data between different formats required for network communications, local storage, and application output.
Integration with Projects
Developers can easily integrate Store5 into their Android and Multiplatform projects. An example setup for Android is as follows:
implementation "org.mobilenativefoundation.store:store5:5.1.0-alpha05"
For multiplatform projects that target Common, JVM, Native, and JS platforms:
commonMain {
dependencies {
implementation("org.mobilenativefoundation.store:store5:5.1.0-alpha05")
}
}
Getting Started with Store5
Building your first Store involves defining a path between your data's network source and its local persistence. A simple example of building a store might look like this:
StoreBuilder
.from<Key, Network, Output, Local>(fetcher, sourceOfTruth)
.converter(converter)
.validator(validator)
.build(updater, bookkeeper)
Store Operations
Store5 provides a straightforward API for performing data operations:
- Creating: Allows adding new data elements.
store.write(
request = StoreWriteRequest.of<Key, Output, Response>(
key = key,
value = value
)
)
- Reading: Retrieves data from the cache or network.
store.stream<Response>(request = StoreReadRequest.cached(key, refresh = false))
- Updating: Updates existing data records.
store.write(
request = StoreWriteRequest.of<Key, Output, Response>(
key = key,
value = newValue
)
)
- Deleting: Removes data from the store.
store.clear(key)
Licensing
Store5 is distributed under the Apache License, Version 2.0, ensuring that it is freely available for both personal and commercial use, subject to the terms of the license.
In summary, Store5 is a versatile and easy-to-integrate library for developers looking to efficiently manage data flows within mobile applications. Its comprehensive set of tools and clear system architecture makes it an excellent choice for building responsive, data-driven applications.