All Downloads are FREE. Search and download functionalities are using the official Maven repository.

kernl.data.repo.Factory.kt Maven / Gradle / Ivy

Go to download

Kernl: A Kotlin Symbol Processing (KSP) library for automatic repository generation.

There is a newer version: 0.0.1-beta6
Show newest version
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)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy