diff --git a/cache/src/commonMain/kotlin/opensavvy.cache/BatchingCacheAdapter.kt b/cache/src/commonMain/kotlin/opensavvy.cache/BatchingCacheAdapter.kt --- a/cache/src/commonMain/kotlin/opensavvy.cache/BatchingCacheAdapter.kt +++ b/cache/src/commonMain/kotlin/opensavvy.cache/BatchingCacheAdapter.kt @@ -10,7 +10,6 @@ import kotlinx.coroutines.launch import opensavvy.logger.Logger.Companion.error import opensavvy.logger.loggerFor -import opensavvy.state.Identifier import opensavvy.state.slice.Slice import kotlin.coroutines.CoroutineContext import kotlin.coroutines.coroutineContext @@ -25,7 +24,7 @@ * * Unlike [CacheAdapter], this class is able to group requests together. */ -class BatchingCacheAdapter( +class BatchingCacheAdapter( context: CoroutineContext, /** * The number of workers batching the requests. @@ -135,7 +134,7 @@ } companion object { - fun batchingCache( + fun batchingCache( context: CoroutineContext, workers: Int = 1, transform: suspend FlowCollector>>.(Set) -> Unit, diff --git a/cache/src/commonMain/kotlin/opensavvy.cache/Cache.kt b/cache/src/commonMain/kotlin/opensavvy.cache/Cache.kt --- a/cache/src/commonMain/kotlin/opensavvy.cache/Cache.kt +++ b/cache/src/commonMain/kotlin/opensavvy.cache/Cache.kt @@ -1,7 +1,6 @@ package opensavvy.cache import kotlinx.coroutines.flow.Flow -import opensavvy.state.Identifier import opensavvy.state.slice.Slice /** @@ -35,14 +34,14 @@ * The first element of the chain, and therefore the one responsible for actually starting the request, is [CacheAdapter] or [BatchingCacheAdapter]. * Note that both have a few implementation differences, it is not recommended to use them directly without chaining under another implementation. */ -interface Cache { +interface Cache { /** * Gets the value associated with an [id] in this cache. * - * This function returns a [State] instance synchronously: it is safe to call in synchronous-only areas of the program, + * This function returns a [Flow] instance synchronously: it is safe to call in synchronous-only areas of the program, * such as inside the body of a UI component. - * You can then subscribe to the [State] to access the actual values. + * You can then subscribe to the [Flow] to access the actual values. */ operator fun get(id: I): Flow> diff --git a/cache/src/commonMain/kotlin/opensavvy.cache/CacheAdapter.kt b/cache/src/commonMain/kotlin/opensavvy.cache/CacheAdapter.kt --- a/cache/src/commonMain/kotlin/opensavvy.cache/CacheAdapter.kt +++ b/cache/src/commonMain/kotlin/opensavvy.cache/CacheAdapter.kt @@ -5,7 +5,6 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow import opensavvy.state.Failure -import opensavvy.state.Identifier import opensavvy.state.slice.Slice /** @@ -14,7 +13,7 @@ * This is not a valid implementation of a cache (it doesn't do any caching), and only serves as a link between caches * and the underlying network APIs. */ -class CacheAdapter( +class CacheAdapter( val query: suspend (I) -> Slice, ) : Cache { @@ -33,7 +32,7 @@ } companion object { - fun cache(transform: suspend EffectScope.(I) -> T) = + fun cache(transform: suspend EffectScope.(I) -> T) = CacheAdapter { either { transform(it) } } } } diff --git a/cache/src/commonMain/kotlin/opensavvy.cache/ExpirationCache.kt b/cache/src/commonMain/kotlin/opensavvy.cache/ExpirationCache.kt --- a/cache/src/commonMain/kotlin/opensavvy.cache/ExpirationCache.kt +++ b/cache/src/commonMain/kotlin/opensavvy.cache/ExpirationCache.kt @@ -11,7 +11,6 @@ import opensavvy.logger.Logger.Companion.debug import opensavvy.logger.Logger.Companion.trace import opensavvy.logger.loggerFor -import opensavvy.state.Identifier import opensavvy.state.slice.Slice import kotlin.coroutines.CoroutineContext import kotlin.coroutines.EmptyCoroutineContext @@ -27,7 +26,7 @@ * .expireAfter(5.minutes, Job()) * ``` */ -class ExpirationCache( +class ExpirationCache( /** * The previous cache layer, from which values will be expired. */ @@ -114,7 +113,7 @@ * * @see ExpirationCache */ - fun Cache.expireAfter(duration: Duration, context: CoroutineContext) = + fun Cache.expireAfter(duration: Duration, context: CoroutineContext) = ExpirationCache(this, duration, context) } } diff --git a/cache/src/commonMain/kotlin/opensavvy.cache/MemoryCache.kt b/cache/src/commonMain/kotlin/opensavvy.cache/MemoryCache.kt --- a/cache/src/commonMain/kotlin/opensavvy.cache/MemoryCache.kt +++ b/cache/src/commonMain/kotlin/opensavvy.cache/MemoryCache.kt @@ -7,7 +7,6 @@ import opensavvy.cache.MemoryCache.Companion.cachedInMemory import opensavvy.logger.Logger.Companion.trace import opensavvy.logger.loggerFor -import opensavvy.state.Identifier import opensavvy.state.Progression import opensavvy.state.ProgressionReporter.Companion.progressionReporter import opensavvy.state.ProgressionReporter.Companion.report @@ -33,7 +32,7 @@ * .expireAfter(2.minutes) * ``` */ -class MemoryCache( +class MemoryCache( private val upstream: Cache, context: CoroutineContext = EmptyCoroutineContext, ) : Cache { @@ -176,6 +175,6 @@ } companion object { - fun Cache.cachedInMemory(context: CoroutineContext) = MemoryCache(this, context) + fun Cache.cachedInMemory(context: CoroutineContext) = MemoryCache(this, context) } } diff --git a/cache/src/commonTest/kotlin/opensavvy.cache/CacheTest.kt b/cache/src/commonTest/kotlin/opensavvy.cache/CacheTest.kt --- a/cache/src/commonTest/kotlin/opensavvy.cache/CacheTest.kt +++ b/cache/src/commonTest/kotlin/opensavvy.cache/CacheTest.kt @@ -27,7 +27,7 @@ level = LogLevel.TRACE } - private data class IntId(val id: Int) : Identifier { + private data class IntId(val id: Int) { override fun toString() = "Id($id)" } diff --git a/spine/src/commonMain/kotlin/opensavvy.spine/Id.kt b/spine/src/commonMain/kotlin/opensavvy.spine/Id.kt --- a/spine/src/commonMain/kotlin/opensavvy.spine/Id.kt +++ b/spine/src/commonMain/kotlin/opensavvy.spine/Id.kt @@ -1,13 +1,12 @@ package opensavvy.spine import kotlinx.serialization.Serializable -import opensavvy.state.Identifier @Serializable data class Id( val service: Route.Segment, val resource: Route, -) : Identifier { +) { constructor(service: String, resource: Route) : this(Route.Segment(service), resource) diff --git a/state/src/commonMain/kotlin/opensavvy.state/Identifier.kt b/state/src/commonMain/kotlin/opensavvy.state/Identifier.kt deleted file mode 100644 --- a/state/src/commonMain/kotlin/opensavvy.state/Identifier.kt +++ /dev/null @@ -1,12 +0,0 @@ -package opensavvy.state - -/** - * Simple marker interface to identify an object. - * - * ### Contract - * - * In the following section, "the same" and "different" refer to the [equals] method. - * - If two implementations of [Identifier] are the same, the object their refer to must be the same. - * - Different implementations of [Identifier] are allowed to refer to the same object, however this is not recommended as it negatively affects caches. - */ -interface Identifier diff --git a/state/src/commonTest/kotlin/opensavvy.state/SliceTest.kt b/state/src/commonTest/kotlin/opensavvy.state/SliceTest.kt --- a/state/src/commonTest/kotlin/opensavvy.state/SliceTest.kt +++ b/state/src/commonTest/kotlin/opensavvy.state/SliceTest.kt @@ -20,7 +20,7 @@ class SliceTest { - private data class IntId(val id: Int) : Identifier { + private data class IntId(val id: Int) { suspend fun request() = slice { val id = this@IntId diff --git a/backbone/src/commonMain/kotlin/opensavvy/backbone/Ref.kt b/backbone/src/commonMain/kotlin/opensavvy/backbone/Ref.kt --- a/backbone/src/commonMain/kotlin/opensavvy/backbone/Ref.kt +++ b/backbone/src/commonMain/kotlin/opensavvy/backbone/Ref.kt @@ -3,7 +3,6 @@ import opensavvy.backbone.Backbone.Companion.request import opensavvy.backbone.Ref.Companion.directRequest import opensavvy.backbone.Ref.Companion.request -import opensavvy.state.Identifier /** * A reference to a specific [object][O]. @@ -17,7 +16,7 @@ * * @param O The object this reference refers to. */ -interface Ref : Identifier { +interface Ref { /** * The [Backbone] responsible for this reference.