Skip to content

Commit 384bc41

Browse files
Use StateFlow in FlowUseCase4ViewModel.kt
1 parent d7511e8 commit 384bc41

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

app/src/main/java/com/lukaslechner/coroutineusecasesonandroid/usecases/flow/usecase4/FlowUseCase4ViewModel.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,11 @@ class FlowUseCase4ViewModel(
1414
.map { stockList ->
1515
UiState.Success(stockList) as UiState
1616
}
17-
.onStart {
18-
emit(UiState.Loading)
19-
}
2017
.onCompletion {
2118
Timber.tag("Flow").d("Flow has completed.")
22-
}.shareIn(
19+
}.stateIn(
2320
scope = viewModelScope,
24-
started = SharingStarted.WhileSubscribed(stopTimeoutMillis = 5000),
25-
replay = 1
21+
initialValue = UiState.Loading,
22+
started = SharingStarted.WhileSubscribed(stopTimeoutMillis = 5000)
2623
)
2724
}

0 commit comments

Comments
 (0)