• Stars
    star
    3,177
  • Rank 14,139 (Top 0.3 %)
  • Language
    Kotlin
  • License
    Apache License 2.0
  • Created almost 5 years ago
  • Updated 29 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Kotlin Multiplatform library for building network-resilient applications

Store5

codecov

Full documentation can be found on our website!

Concepts

  • Store is a typed repository that returns a flow of Data /Loading /Error from local and network data sources
  • MutableStore is a mutable repository implementation that allows create (C), read (R), update (U), and delete (D) operations for local and network resources
  • SourceOfTruth persists items
  • Fetcher defines how data will be fetched over network
  • Updater defines how local changes will be pushed to network
  • Bookkeeper tracks metadata of local changes and records synchronization failures
  • Validator returns whether an item is valid
  • Converter converts items between Network /Local /Output representations

Including Store In Your Project

Note

AtomicFU is required (#503)

Android

implementation "org.mobilenativefoundation.store:store5:5.0.0-beta02"
implementation "org.jetbrains.kotlinx:atomicfu:0.18.5"

Multiplatform (Common, JVM, Native, JS)

commonMain {
  dependencies {
    implementation("org.mobilenativefoundation.store:store5:5.0.0-beta02")
    implementation("org.jetbrains.kotlinx:atomicfu:0.18.5")
  }
}

Getting Started

Building Your First Store

StoreBuilder
  .from<Key, Network, Output, Local>(fetcher, sourceOfTruth)
  .converter(converter)
  .validator(validator)
  .build(updater, bookkeeper)

Creating

Request
store.write(
  request = StoreWriteRequest.of<Key, Output, Response>(
    key = key,
    value = value
  )
)
Response
1. StoreWriteResponse.Success.Typed<Response>(response)

Reading

Request
store.stream<Response>(request = StoreReadRequest.cached(key, refresh = false))
Response
1. StoreReadResponse.Data(value, origin = StoreReadResponseOrigin.Cache)

Updating

Request
store.write(
  request = StoreWriteRequest.of<Key, Output, Response>(
    key = key,
    value = newValue
  )
)
Response
1. StoreWriteResponse.Success.Typed<Response>(response)

Deleting

Request
store.clear(key)

License

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.