@@ -243,24 +243,36 @@ The datasource exposes a `Flow` which is built with the `flow{}` flow builder. I
243243A ` LiveData ` property that exposes the ` UiState ` in the ` ViewModel ` is created by using the ` .asLiveData() ` terminal operator.
244244This use case also shows how to use the ` map ` intermediate operator and the ` onStart ` lifecycle operator.
245245
246+ [[ code viewmodel] ( app/src/main/java/com/lukaslechner/coroutineusecasesonandroid/usecases/flow/usecase1/FlowUseCase1ViewModel.kt )]
247+ [[ code datasource] ( app/src/main/java/com/lukaslechner/coroutineusecasesonandroid/usecases/flow/usecase1/StockPriceDataSource.kt )]
248+
246249### 2. Basic Flow Intermediate Operators
247250
248251The second use case is an extension of the first one.
249252It uses some basic intermediate operators, like ` withIndex ` , ` map ` , ` take ` and ` filter ` .
250253
254+ [[ code viewmodel] ( app/src/main/java/com/lukaslechner/coroutineusecasesonandroid/usecases/flow/usecase2/FlowUseCase2ViewModel.kt )]
255+ [[ code datasource] ( app/src/main/java/com/lukaslechner/coroutineusecasesonandroid/usecases/flow/usecase2/StockPriceDataSource.kt )]
256+
251257### 3. Flow Exception Handling
252258
253259The third use case shows how to properly implement exception handling with flows.
254260
255261It uses the ` catch ` operator to handle exceptions of our flow in the ` ViewModel ` and uses the ` retry ` operator to retry failed network requests in the ` DataSource ` .
256262
263+ [[ code viewmodel] ( app/src/main/java/com/lukaslechner/coroutineusecasesonandroid/usecases/flow/usecase3/FlowUseCase3ViewModel.kt )]
264+ [[ code datasource] ( app/src/main/java/com/lukaslechner/coroutineusecasesonandroid/usecases/flow/usecase3/StockPriceDataSource.kt )]
265+
257266### 4. Exposing Flows in the ViewModel
258267
259268This use case shows how to expose flows (a ` StateFlow ` to be precise) in the ` ViewModel ` instead of a ` LiveData ` property.
260269The ` statIn ` operator is used to convert the ordinary, cold ` Flow ` into a hot ` StateFlow ` .
261270
262271In the ` Activity ` , the ` repeadOnLifecycle ` suspend function is used to collect emissions of the ` StateFlow ` in a lifecycle-aware manner.
263272
273+ [[ code viewmodel] ( app/src/main/java/com/lukaslechner/coroutineusecasesonandroid/usecases/flow/usecase4/FlowUseCase1ViewModel.kt )]
274+ [[ code datasource] ( app/src/main/java/com/lukaslechner/coroutineusecasesonandroid/usecases/flow/usecase4/StockPriceDataSource.kt )]
275+
264276## Author
265277
266278![ LukasLechner] ( documentation/images/lukle.png )
0 commit comments