Skip to content

Commit

Permalink
fixing an error with default values
Browse files Browse the repository at this point in the history
  • Loading branch information
gmerinojimenez committed Nov 24, 2021
1 parent 9d431be commit 4d06f01
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ class TweakDemoApplication : Application() {
editableBoolean(
key = "value2",
name = "Value 2",
defaultValue = true,
)
editableLong(
key = "value4",
name = "Value 4",
defaultValue = 0L,
defaultValue = 42L,
)

button(
key = "button1",
name = "Demo button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,15 @@ class TweaksBusinessLogic @Inject constructor(
val defaultValueFlow: StateFlow<T>? = editableCasted.defaultValue
val initialValue = defaultValueFlow?.value

val mergedFlow: Flow<T?> = if (defaultValueFlow != null) merge(getFromStorage(entry), defaultValueFlow) else getFromStorage(entry)
val mergedFlow: Flow<T?> = if (defaultValueFlow != null) {
merge(
getFromStorage(entry)
.filter { it != null },
defaultValueFlow
)
} else {
getFromStorage(entry)
}

return mergedFlow.stateIn(
scope = CoroutineScope(Dispatchers.Default),
Expand Down

0 comments on commit 4d06f01

Please sign in to comment.