Skip to content

Commit

Permalink
create a produceToolState Composable for the ToolsRepository
Browse files Browse the repository at this point in the history
  • Loading branch information
frett committed Feb 27, 2024
1 parent fdaa590 commit 40de289
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package org.cru.godtools.db.repository

import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.remember
import java.util.Locale
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
import org.cru.godtools.model.Tool

Expand Down Expand Up @@ -42,3 +46,7 @@ interface ToolsRepository {
suspend fun deleteIfNotFavorite(code: String)
// endregion Sync Methods
}

@Composable
fun ToolsRepository.produceToolState(toolCode: String?) =
remember(toolCode) { toolCode?.let { findToolFlow(it) } ?: flowOf(null) }.collectAsState(null)

0 comments on commit 40de289

Please sign in to comment.