Skip to content

Commit

Permalink
noop stateflows
Browse files Browse the repository at this point in the history
  • Loading branch information
gmerinojimenez committed Nov 24, 2021
1 parent 04d9adb commit a583349
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions library/src/noop/java/com/gmerinojimenez/tweaks/Tweaks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ import androidx.compose.runtime.Composable
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import com.gmerinojimenez.tweaks.domain.*
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow

class Tweaks {

internal lateinit var tweaksGraph: TweaksGraph
private val keyToEntryValueMap: MutableMap<String, TweakEntry<*>> = mutableMapOf()

@Suppress("UNCHECKED_CAST")
fun <T> getTweakValue(key: String): Flow<T?> {
fun <T> getTweakValue(key: String): StateFlow<T?> {
val entry= keyToEntryValueMap[key] as TweakEntry<T>
return getTweakValue(entry)
}

@Suppress("UNCHECKED_CAST")
fun <T> getTweakValue(entry: TweakEntry<T>): Flow<T?> = when (entry as Modifiable) {
fun <T> getTweakValue(entry: TweakEntry<T>): StateFlow<T?> = when (entry as Modifiable) {
is ReadOnly<*> -> (entry as ReadOnly<T>).value
is Editable<*> -> (entry as Editable<T>).defaultValue ?: flow { emit(null) }
is Editable<*> -> (entry as Editable<T>).defaultValue ?: MutableStateFlow(null)
}

private fun initialize(tweaksGraph: TweaksGraph) {
Expand Down

0 comments on commit a583349

Please sign in to comment.