This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RatesViewModel constructor( | |
private val ratesRepository: RatesRepository, | |
) : ViewModel() { | |
val state = MutableStateFlow(RatesUiState(isLoading = true)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RatesViewModel constructor( | |
private val ratesRepository: RatesRepository, | |
) : ViewModel() { | |
private val _state = MutableStateFlow(RatesUiState(isLoading = true)) | |
val state: StateFlow<RatesUiState> | |
get() = _state.asStateFlow() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SearchViewModel @Inject constructor( | |
private val searchUseCase: dagger.Lazy<SearchUseCase>, | |
) : ViewModel() { | |
private val searchQuery = MutableStateFlow("") | |
val uiState: LiveData<SearchUiState> = searchQuery | |
.debounce(DEBOUNCE_TIME_IN_MILLIS) | |
.asLiveData() | |
.switchMap(::createUiState) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SearchViewModel @Inject constructor( | |
private val searchUseCase: SearchUseCase, | |
@IoDispatcher val ioDispatcher: CoroutineDispatcher | |
) : ViewModel() { | |
private val searchQuery = MutableStateFlow("") | |
private val _uiState = MutableLiveData<SearchUiState>() | |
val uiState = _uiState |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SearchViewModel @Inject constructor( | |
private val searchUseCase: dagger.Lazy<SearchUseCase>, | |
private val wordsUseCase: GetWordsUseCase, | |
) : ViewModel() { | |
data class UiState( | |
val isLoading: Boolean = true, | |
val words: List<String> = emptyList() | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SearchViewModel @Inject constructor( | |
private val searchUseCase: dagger.Lazy<SearchUseCase>, | |
private val wordsUseCase: GetWordsUseCase, | |
) : ViewModel() { | |
data class UiState( | |
val isLoading: Boolean, | |
val words: List<String> = emptyList() | |
) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
context(Fragment) | |
inline fun <T> Flow<T>.collectInFragment( | |
crossinline onCollect: suspend (T) -> Unit | |
) = viewLifecycleOwner.lifecycleScope.launch { | |
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) { | |
collectLatest { | |
onCollect(it) | |
} | |
} | |
} |
NewerOlder