2022-12-23 19:04:24 +00:00
< div align = "center" >
< img src = "Images/friendly_robot.png" width = "120" / >
< h1 style = "font-size:48px" > Store5< / h1 >
< / div >
2020-01-19 02:06:59 +00:00
2023-04-20 22:15:16 +00:00
[![codecov ](https://codecov.io/gh/MobileNativeFoundation/Store/branch/main/graph/badge.svg?token=0UCmG3QHPf )](https://codecov.io/gh/MobileNativeFoundation/Store)
2022-12-23 19:04:24 +00:00
< div align = "center" >
< h4 > Full documentation can be found on our < a href = "https://mobilenativefoundation.github.io/Store/" > website< / a > !< / h4 >
2023-10-07 18:38:51 +00:00
< h4 > Join our official Slack on < a href = "https://kotlinlang.slack.com/archives/C06007Z01HU" > kotlinlang< / a > !< / h4 >
2022-12-23 19:04:24 +00:00
< / div >
2017-01-04 19:17:53 +00:00
2022-12-23 19:04:24 +00:00
### Concepts
2020-02-14 10:59:31 +00:00
2022-12-23 19:04:24 +00:00
- [Store ](https://mobilenativefoundation.github.io/Store/store/store/ ) is a typed repository that returns a flow
of [Data ](https://github.com/MobileNativeFoundation/Store/blob/main/store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/StoreReadResponse.kt#L39 )
/[Loading](https://github.com/MobileNativeFoundation/Store/blob/main/store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/StoreReadResponse.kt#L34)
/[Error](https://github.com/MobileNativeFoundation/Store/blob/main/store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/StoreReadResponse.kt#L51)
from local and network data sources
- [MutableStore ](https://mobilenativefoundation.github.io/Store/mutable-store/building/overview/ ) is a mutable repository implementation that allows create ** (C)**, read ** (R)**,
update ** (U)**, and delete ** (D)** operations for local and network resources
- [SourceOfTruth ](https://mobilenativefoundation.github.io/Store/mutable-store/building/implementations/source-of-truth/ ) persists items
- [Fetcher ](https://mobilenativefoundation.github.io/Store/mutable-store/building/implementations/fetcher/ ) defines how data will be fetched over network
- [Updater ](https://mobilenativefoundation.github.io/Store/mutable-store/building/implementations/updater/ ) defines how local changes will be pushed to network
- [Bookkeeper ](https://mobilenativefoundation.github.io/Store/mutable-store/building/implementations/bookkeeper/ ) tracks metadata of local changes and records
synchronization failures
- [Validator ](https://mobilenativefoundation.github.io/Store/mutable-store/building/implementations/validator/ ) returns whether an item is valid
- [Converter ](https://mobilenativefoundation.github.io/Store/mutable-store/building/implementations/converter/ ) converts items
between [Network ](https://mobilenativefoundation.github.io/Store/mutable-store/building/generics/network )
/[Local](https://mobilenativefoundation.github.io/Store/mutable-store/building/generics/sot)
/[Output](https://mobilenativefoundation.github.io/Store/mutable-store/building/generics/common) representations
2017-01-04 19:17:53 +00:00
2022-12-23 19:04:24 +00:00
### Including Store In Your Project
2017-01-04 19:17:53 +00:00
2023-01-16 21:28:49 +00:00
> **Note**
>
> **[AtomicFU](https://github.com/Kotlin/kotlinx-atomicfu) is required ([#503](https://github.com/MobileNativeFoundation/Store/issues/503))**
2020-01-19 02:06:59 +00:00
2023-01-16 21:28:49 +00:00
#### Android
2023-01-16 21:28:45 +00:00
```kotlin
2023-09-14 16:33:26 +00:00
implementation "org.mobilenativefoundation.store:store5:5.0.0"
2023-02-25 01:01:42 +00:00
implementation "org.jetbrains.kotlinx:atomicfu:0.18.5"
2018-03-29 16:25:03 +00:00
```
2018-07-27 01:58:45 +00:00
2022-12-23 19:04:24 +00:00
#### Multiplatform (Common, JVM, Native, JS)
2018-03-29 16:25:03 +00:00
2023-01-16 21:28:45 +00:00
```kotlin
commonMain {
dependencies {
2023-09-14 16:33:26 +00:00
implementation("org.mobilenativefoundation.store:store5:5.0.0")
2023-02-25 01:01:42 +00:00
implementation("org.jetbrains.kotlinx:atomicfu:0.18.5")
2023-01-16 21:28:45 +00:00
}
2018-03-29 16:25:03 +00:00
}
```
2022-12-23 19:04:24 +00:00
### Getting Started
2023-01-16 21:28:45 +00:00
2022-12-23 19:04:24 +00:00
#### Building Your First Store
2018-07-27 01:58:45 +00:00
2019-11-05 02:11:07 +00:00
```kotlin
2019-12-06 15:59:08 +00:00
StoreBuilder
2022-12-23 19:04:24 +00:00
.from< Key , Network , Output , Local > (fetcher, sourceOfTruth)
.converter(converter)
.validator(validator)
.build(updater, bookkeeper)
2017-01-04 19:17:53 +00:00
```
2022-12-23 19:04:24 +00:00
#### Creating
2017-01-04 19:17:53 +00:00
2022-12-23 19:04:24 +00:00
##### Request
2017-01-04 19:17:53 +00:00
2019-11-05 02:11:07 +00:00
```kotlin
2022-12-23 19:04:24 +00:00
store.write(
request = StoreWriteRequest.of< Key , Output , Response > (
key = key,
value = value
)
)
2017-01-04 19:17:53 +00:00
```
2018-07-27 01:58:45 +00:00
2022-12-23 19:04:24 +00:00
##### Response
2019-11-05 02:11:07 +00:00
2022-12-23 19:04:24 +00:00
```text
1. StoreWriteResponse.Success.Typed< Response > (response)
2019-11-05 02:11:07 +00:00
```
2017-01-04 19:17:53 +00:00
2022-12-23 19:04:24 +00:00
#### Reading
2017-05-19 14:25:04 +00:00
2022-12-23 19:04:24 +00:00
##### Request
2020-01-19 02:06:59 +00:00
```kotlin
2022-12-23 19:04:24 +00:00
store.stream< Response > (request = StoreReadRequest.cached(key, refresh = false))
2020-01-19 02:06:59 +00:00
```
2017-05-19 14:25:04 +00:00
2022-12-23 19:04:24 +00:00
##### Response
2020-01-28 17:02:28 +00:00
2022-12-23 19:04:24 +00:00
```text
1. StoreReadResponse.Data(value, origin = StoreReadResponseOrigin.Cache)
2020-01-28 17:02:28 +00:00
```
2022-12-23 19:04:24 +00:00
#### Updating
2020-01-28 17:02:28 +00:00
2022-12-23 19:04:24 +00:00
##### Request
2020-01-28 17:02:28 +00:00
```kotlin
2022-12-23 19:04:24 +00:00
store.write(
request = StoreWriteRequest.of< Key , Output , Response > (
key = key,
value = newValue
)
)
2020-01-28 17:02:28 +00:00
```
2022-12-23 19:04:24 +00:00
##### Response
2020-01-28 17:02:28 +00:00
2022-12-23 19:04:24 +00:00
```text
1. StoreWriteResponse.Success.Typed< Response > (response)
2020-01-28 17:02:28 +00:00
```
2022-12-23 19:04:24 +00:00
#### Deleting
2020-01-28 17:02:28 +00:00
2022-12-23 19:04:24 +00:00
##### Request
2020-01-28 17:02:28 +00:00
```kotlin
2022-12-23 19:04:24 +00:00
store.clear(key)
2020-01-29 15:37:14 +00:00
```
2022-01-31 22:49:58 +00:00
2022-12-23 19:04:24 +00:00
### License
2022-01-31 22:49:58 +00:00
2023-01-16 21:28:45 +00:00
```text
Copyright (c) 2022 Mobile Native Foundation.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
```
2022-01-31 22:49:58 +00:00