Skip to content

Commit

Permalink
Add experimental annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
arkivanov committed Jul 8, 2024
1 parent e8bbceb commit 32975fa
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.arkivanov.essenty.instancekeeper

/**
* Marks experimental API in Essenty. An experimental API can be changed or removed at any time.
*/
@RequiresOptIn(level = RequiresOptIn.Level.WARNING)
@Retention(AnnotationRetention.BINARY)
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
annotation class ExperimentalInstanceKeeperApi
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.arkivanov.essenty.instancekeeper

import com.arkivanov.essenty.instancekeeper.InstanceKeeper.SimpleInstance
import com.arkivanov.essenty.utils.internal.ExperimentalEssentyApi
import kotlin.reflect.typeOf

/**
Expand Down Expand Up @@ -29,14 +28,14 @@ inline fun <reified T : InstanceKeeper.Instance> InstanceKeeper.getOrCreate(fact
/**
* A convenience function for [InstanceKeeper.getOrCreate].
*/
@ExperimentalEssentyApi
@ExperimentalInstanceKeeperApi
inline fun <reified T : InstanceKeeper.Instance> InstanceKeeperOwner.retainedInstance(key: Any, factory: () -> T): T =
instanceKeeper.getOrCreate(key = key, factory = factory)

/**
* A convenience function for [InstanceKeeper.getOrCreate].
*/
@ExperimentalEssentyApi
@ExperimentalInstanceKeeperApi
inline fun <reified T : InstanceKeeper.Instance> InstanceKeeperOwner.retainedInstance(factory: () -> T): T =
instanceKeeper.getOrCreate(factory = factory)

Expand All @@ -62,13 +61,13 @@ inline fun <reified T> InstanceKeeper.getOrCreateSimple(factory: () -> T): T =
/**
* A convenience function for [InstanceKeeper.getOrCreateSimple].
*/
@ExperimentalEssentyApi
@ExperimentalInstanceKeeperApi
inline fun <reified T> InstanceKeeperOwner.retainedSimpleInstance(key: Any, factory: () -> T): T =
instanceKeeper.getOrCreateSimple(key = key, factory = factory)

/**
* A convenience function for [InstanceKeeper.getOrCreateSimple].
*/
@ExperimentalEssentyApi
@ExperimentalInstanceKeeperApi
inline fun <reified T> InstanceKeeperOwner.retainedSimpleInstance(factory: () -> T): T =
instanceKeeper.getOrCreateSimple(factory = factory)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.arkivanov.essenty.statekeeper

/**
* Marks experimental API in Essenty. An experimental API can be changed or removed at any time.
*/
@RequiresOptIn(level = RequiresOptIn.Level.WARNING)
@Retention(AnnotationRetention.BINARY)
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
annotation class ExperimentalStateKeeperApi
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.arkivanov.essenty.statekeeper

import com.arkivanov.essenty.utils.internal.ExperimentalEssentyApi
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.KSerializer
import kotlinx.serialization.descriptors.SerialDescriptor
Expand All @@ -18,15 +17,15 @@ import kotlin.reflect.KClass
/**
* Creates a polymorphic [KSerializer] for the specified class of type [T] using the specified [module].
*/
@ExperimentalEssentyApi
@ExperimentalStateKeeperApi
@ExperimentalSerializationApi
inline fun <reified T : Any> polymorphicSerializer(module: SerializersModule): KSerializer<T> =
polymorphicSerializer(baseClass = T::class, module = module)

/**
* Creates a polymorphic [KSerializer] for the specified [baseClass] class using the specified [module].
*/
@ExperimentalEssentyApi
@ExperimentalStateKeeperApi
@ExperimentalSerializationApi
fun <T : Any> polymorphicSerializer(baseClass: KClass<T>, module: SerializersModule): KSerializer<T> =
PolymorphicSerializer(baseClass = baseClass, module = module)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.arkivanov.essenty.statekeeper

import com.arkivanov.essenty.utils.internal.ExperimentalEssentyApi
import kotlinx.serialization.KSerializer
import kotlin.properties.PropertyDelegateProvider
import kotlin.properties.ReadOnlyProperty
Expand All @@ -21,7 +20,7 @@ import kotlin.reflect.KProperty
* returns an object of type [T].
* @return [PropertyDelegateProvider] of type [T], typically used to define a delegated property.
*/
@ExperimentalEssentyApi
@ExperimentalStateKeeperApi
inline fun <T, S : Any> StateKeeper.saveable(
serializer: KSerializer<S>,
crossinline state: (T) -> S,
Expand Down Expand Up @@ -49,7 +48,7 @@ inline fun <T, S : Any> StateKeeper.saveable(
* returns an object of type [T].
* @return [PropertyDelegateProvider] of type [T], typically used to define a delegated property.
*/
@ExperimentalEssentyApi
@ExperimentalStateKeeperApi
inline fun <T, S : Any> StateKeeperOwner.saveable(
serializer: KSerializer<S>,
crossinline state: (T) -> S,
Expand All @@ -74,7 +73,7 @@ inline fun <T, S : Any> StateKeeperOwner.saveable(
* @param init a function returning the initial value of type [T].
* @return [PropertyDelegateProvider] of type [T], typically used to define a delegated property.
*/
@ExperimentalEssentyApi
@ExperimentalStateKeeperApi
inline fun <T : Any> StateKeeper.saveable(
serializer: KSerializer<T>,
key: String? = null,
Expand Down Expand Up @@ -106,7 +105,7 @@ inline fun <T : Any> StateKeeper.saveable(
* @param init a function returning the initial value of type [T].
* @return [PropertyDelegateProvider] of type [T], typically used to define a delegated property.
*/
@ExperimentalEssentyApi
@ExperimentalStateKeeperApi
inline fun <T : Any> StateKeeperOwner.saveable(
serializer: KSerializer<T>,
key: String? = null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.arkivanov.essenty.statekeeper

import com.arkivanov.essenty.utils.internal.ExperimentalEssentyApi
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
Expand Down Expand Up @@ -30,7 +29,7 @@ class PolymorphicSerializerTest {
@Serializable
private data class Some2(val data: SerializableData) : Some

@OptIn(ExperimentalEssentyApi::class, ExperimentalSerializationApi::class)
@OptIn(ExperimentalStateKeeperApi::class, ExperimentalSerializationApi::class)
private object SomeSerializer : KSerializer<Some> by polymorphicSerializer(
SerializersModule {
polymorphic(Some::class) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.arkivanov.essenty.statekeeper

import com.arkivanov.essenty.utils.internal.ExperimentalEssentyApi
import kotlinx.serialization.builtins.serializer
import kotlin.test.Test
import kotlin.test.assertEquals

@OptIn(ExperimentalEssentyApi::class)
@OptIn(ExperimentalStateKeeperApi::class)
class StateKeeperExtTest {

@Test
Expand Down

0 comments on commit 32975fa

Please sign in to comment.