Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

209
Visualizações
MVI where do I store non-ui data in Viewmodel or Model?

DownloadView initially downloads a Record from a Performance and when a DownloadAudioFile button is clicked the FileService will download the Record's Audio file.

Is there a better place to store Performance, Record, and Audio other than private variables? I was thinking about creating DownloadModel, a model class for the DownloadView that can handle data that isn't being shown to UI.

I thought about only using ViewState but it feels weird accessing and storing data in there when it isn't shown to the UI. Record could be accessed from ViewState but what about Performance or Audio?

Just within the MVI context, not talking about storing it on a db or something.

class DownloadViewModel(val fileService: FileService, val scope: CoroutineScope,private val performance: Performance) {
    private val _viewState: MutableStateFlow<ViewState> = MutableStateFlow(ViewState())
    val viewState = _viewState.asStateFlow()

    private val _oneShotEvents = Channel<OneShotEvent>(Channel.BUFFERED)
    val oneShotEvents = _oneShotEvents.receiveAsFlow()

    //val model: DownloadModel = DownloadModel(performance)
    private lateinit var record: Record

    init {
        scope.launch {
           record = fileService.performanceRequest(performance)
            _viewState.value = _viewState.value.copy( record = record)
        }

    }
    fun onAction(action: UiAction){
        when(action){
            UiAction.DownloadAudioFile -> {
                scope.launch {
                    fileService.downloadAudio()
                }
            }
        }
    }

    sealed class UiAction{
        object DownloadAudioFile: UiAction()
    }

    data class ViewState(val record: models.Record? = null)
    sealed class OneShotEvent{

    }
}
over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda