Skip to content

Commit

Permalink
[#535] Update state flow to use asStateFlow in base viewmodel classes
Browse files Browse the repository at this point in the history
  • Loading branch information
kaungkhantsoe committed Oct 20, 2023
1 parent f78d181 commit 1d51e5d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package co.nimblehq.sample.compose.ui.base

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import co.nimblehq.sample.compose.lib.IsLoading
import co.nimblehq.sample.compose.ui.AppDestination
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
Expand All @@ -15,13 +14,13 @@ abstract class BaseViewModel : ViewModel() {
private var loadingCount: Int = 0

private val _isLoading = MutableStateFlow(false)
val isLoading: StateFlow<IsLoading> = _isLoading
val isLoading = _isLoading.asStateFlow()

protected val _error = MutableSharedFlow<Throwable>()
val error: SharedFlow<Throwable> = _error
val error = _error.asSharedFlow()

protected val _navigator = MutableSharedFlow<AppDestination>()
val navigator: SharedFlow<AppDestination> = _navigator
val navigator = _navigator.asSharedFlow()

/**
* To show loading manually, should call `hideLoading` after
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package co.nimblehq.template.compose.ui.base

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import co.nimblehq.template.compose.lib.IsLoading
import co.nimblehq.template.compose.ui.AppDestination
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
Expand All @@ -15,13 +14,13 @@ abstract class BaseViewModel : ViewModel() {
private var loadingCount: Int = 0

private val _isLoading = MutableStateFlow(false)
val isLoading: StateFlow<IsLoading> = _isLoading
val isLoading = _isLoading.asStateFlow()

protected val _error = MutableSharedFlow<Throwable>()
val error: SharedFlow<Throwable> = _error
val error = _error.asSharedFlow()

protected val _navigator = MutableSharedFlow<AppDestination>()
val navigator: SharedFlow<AppDestination> = _navigator
val navigator = _navigator.asSharedFlow()

/**
* To show loading manually, should call `hideLoading` after
Expand Down

0 comments on commit 1d51e5d

Please sign in to comment.