Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

207
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!