Skip to content

Commit

Permalink
migrate from state to stateflow in ViewModel
Browse files Browse the repository at this point in the history
  • Loading branch information
its-me-debk007 committed Sep 2, 2024
1 parent eea73bd commit 71beee3
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package com.debk007.template.presentation.viewmodel

import androidx.compose.runtime.MutableState
import androidx.compose.runtime.State
import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.debk007.template.model.ProductDetailsDto
import com.debk007.template.repository.Repository
import com.debk007.template.util.ApiState
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch
import javax.inject.Inject

Expand All @@ -19,9 +18,9 @@ class HomeViewModel @Inject constructor(
) : ViewModel() {

// TODO: Set UI State
private val _productDetailsState: MutableState<ApiState<ProductDetailsDto>> =
mutableStateOf(ApiState.Loading)
val productDetailsState: State<ApiState<ProductDetailsDto>> get() = _productDetailsState
private val _productDetailsState: MutableStateFlow<ApiState<ProductDetailsDto>> =
MutableStateFlow(ApiState.Loading)
val productDetailsState = _productDetailsState.asStateFlow()

init {
getProductDetails()
Expand Down

0 comments on commit 71beee3

Please sign in to comment.