Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

215
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda