kernl.data.repo.Factory.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Kernl.Runtime Show documentation
Show all versions of Kernl.Runtime Show documentation
Kernl: A Kotlin Symbol Processing (KSP) library for automatic repository generation.
package io.github.mattshoe.shoebox.kernl.data.repo
import io.github.mattshoe.shoebox.kernl.data.repo.associativecache.BaseAssociativeCacheLiveRepository
import io.github.mattshoe.shoebox.kernl.data.repo.nocache.BaseNoCacheRepository
import io.github.mattshoe.shoebox.kernl.data.repo.nocache.NoCacheRepository
import io.github.mattshoe.shoebox.kernl.data.repo.singlecache.BaseSingleCacheLiveRepository
import io.github.mattshoe.shoebox.kernl.data.repo.singlecache.SingleCacheLiveRepository
import kotlin.reflect.KClass
fun noCacheRepository(
fetchData: suspend (TParams) -> TData
): NoCacheRepository {
return object : BaseNoCacheRepository() {
override suspend fun fetch(params: TParams): TData = fetchData(params)
}
}
fun singleCacheLiveRepository(
clazz: KClass,
fetchData: suspend (TParams) -> TData
): SingleCacheLiveRepository {
return object : BaseSingleCacheLiveRepository() {
override val dataType = clazz
override suspend fun fetchData(params: TParams): TData = fetchData(params)
}
}
fun multiSourceLiveRepository(
clazz: KClass,
fetchData: suspend (TParams) -> TData
): io.github.mattshoe.shoebox.kernl.data.repo.associativecache.AssociativeMemoryCacheLiveRepository {
return object : BaseAssociativeCacheLiveRepository() {
override val dataType = clazz
override suspend fun fetchData(params: TParams): TData = fetchData(params)
}
}