Skip to content

Latest commit

 

History

History
80 lines (62 loc) · 2.65 KB

README.md

File metadata and controls

80 lines (62 loc) · 2.65 KB

Bhandar : Simple network/local source repository

Kotlin Alpha Kotlin License

badge-jvm badge-android badge-ios badge-watchos badge-tvos badge-js badge-wasm badge-mac badge-linux badge-windows

Bhandar (ভান্ডার) is a simple repository implementation that can fetch data from a fetching source and (if configured) a store for cached access.

The repository using only one model for simplicity, so the implementation on the sources would need to convert to the shared model definition.

Gradle setup

Kotlin DSL
implementation("com.bidyut.tech.bhandar:bhandar:<version>")
Version Catalogue
[versions]
bhandar = "version"

[libraries]
bhandar = { group = "com.bidyut.tech.bhandar", name = "bhandar", version.ref = "bhandar" }

Configuring a repository

To create a new repository, we need to configure a fetcher and a storage. Let us assume a simple data model and request.

data class Request(
    val id: String,
)

data class DataModel(
    val id: String,
    val value: String,
)

So we need a fetcher like

val fetcher = DataFetcher.of<Request, DataModel> {
    // return Result.success() or Result.failure() based on the response
}

and a storage like

val storage = Storage.of<Request, DataModel>(
    read = { request -> 
        // return flow with the data or null
    },
    write = { request, newValue ->
        // write the data to the storage
    },
)

Optionally both the fetcher and storage can have a different validation check; by default it is just non-null.