Yokan / rebuild
Course 1 8624561

CodeEditorViewModel.kt

composeApp/src/commonMain/kotlin/eu/friedcutlet/yokan/ui/screens/extensions/CodeEditorViewModel.kt

implementation20 lines
1package eu.friedcutlet.yokan.ui.screens.extensions23import androidx.lifecycle.ViewModel4import androidx.lifecycle.viewModelScope5import eu.friedcutlet.yokan.data.YokanRepository6import eu.friedcutlet.yokan.database.DbSource7import kotlinx.coroutines.flow.SharingStarted8import kotlinx.coroutines.flow.StateFlow9import kotlinx.coroutines.flow.stateIn1011/** The stored source row behind the code editor; edits stay in the screen until saved. */12internal class CodeEditorViewModel(13    private val sourceId: Long,14    private val repository: YokanRepository,15) : ViewModel() {16    val source: StateFlow<DbSource?> = repository.observeDbSource(sourceId)17        .stateIn(viewModelScope, SharingStarted.Eagerly, repository.currentDbSource(sourceId))1819    fun save(code: String) = repository.updateSourceCode(sourceId, code)20}21

Search chapters, reference and source filenames.