Skip to content

Commit 107ee58

Browse files
committed
Made ContextKey/ContextElement public
1 parent ecb3538 commit 107ee58

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

reactivestate-core/src/commonMain/kotlin/com/ensody/reactivestate/ContextualVal.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class ContextualVal<T>(
2525
public val name: String,
2626
public var default: (CoroutineContext) -> T,
2727
) {
28-
internal val key = ContextKey(this)
28+
public val key: ContextKey<T> = ContextKey(this)
2929
private val globalDefaultCache by lazy { default(EmptyCoroutineContext) }
3030

3131
/** Gets the value for the current [coroutineContext]. */
@@ -57,15 +57,18 @@ public class ContextualVal<T>(
5757
override fun toString(): String =
5858
"${super.toString()}<$name>"
5959

60-
internal data class ContextKey<T>(val value: ContextualVal<T>) : CoroutineContext.Key<ContextElement<T>>
60+
public class ContextKey<T>(public val value: ContextualVal<T>) : CoroutineContext.Key<ContextElement<T>> {
61+
override fun toString(): String =
62+
"${super.toString()}<$value>"
63+
}
6164

62-
internal class ContextElement<T>(
65+
public class ContextElement<T>(
6366
override val key: ContextKey<T>,
6467
private val valueGetter: (CoroutineContext) -> T,
6568
) : CoroutineContext.Element {
6669
private val value: MutableStateFlow<Wrapped<T>?> = MutableStateFlow(null)
6770

68-
tailrec fun get(context: CoroutineContext): T {
71+
internal tailrec fun get(context: CoroutineContext): T {
6972
value.value?.let { return it.value }
7073
value.compareAndSet(null, Wrapped(valueGetter(context)))
7174
return get(context)

reactivestate-core/src/commonMain/kotlin/com/ensody/reactivestate/ContextualValSuspend.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class ContextualValSuspend<T>(
2525
public val name: String,
2626
public var default: suspend (CoroutineContext) -> T,
2727
) {
28-
internal val key = ContextKey(this)
28+
public val key: ContextKey<T> = ContextKey(this)
2929
private val globalDefaultCache = LazySuspend { default(EmptyCoroutineContext) }
3030

3131
/** Gets the value for the current [coroutineContext]. */
@@ -57,15 +57,18 @@ public class ContextualValSuspend<T>(
5757
override fun toString(): String =
5858
"${super.toString()}<$name>"
5959

60-
internal data class ContextKey<T>(val value: ContextualValSuspend<T>) : CoroutineContext.Key<ContextElement<T>>
60+
public class ContextKey<T>(public val value: ContextualValSuspend<T>) : CoroutineContext.Key<ContextElement<T>> {
61+
override fun toString(): String =
62+
"${super.toString()}<$value>"
63+
}
6164

62-
internal class ContextElement<T>(
65+
public class ContextElement<T>(
6366
override val key: ContextKey<T>,
6467
private val valueGetter: suspend (CoroutineContext) -> T,
6568
) : CoroutineContext.Element {
6669
private val value: MutableStateFlow<Wrapped<T>?> = MutableStateFlow(null)
6770

68-
tailrec suspend fun get(context: CoroutineContext): T {
71+
internal tailrec suspend fun get(context: CoroutineContext): T {
6972
value.value?.let { return it.value }
7073
value.compareAndSet(null, Wrapped(valueGetter(context)))
7174
return get(context)

0 commit comments

Comments
 (0)