Skip to content

Commit 9cf12dc

Browse files
Add references to files for flow use cases in README.md
1 parent c285860 commit 9cf12dc

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -243,24 +243,36 @@ The datasource exposes a `Flow` which is built with the `flow{}` flow builder. I
243243
A `LiveData` property that exposes the `UiState` in the `ViewModel` is created by using the `.asLiveData()` terminal operator.
244244
This 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

248251
The second use case is an extension of the first one.
249252
It 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

253259
The third use case shows how to properly implement exception handling with flows.
254260

255261
It 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

259268
This use case shows how to expose flows (a `StateFlow` to be precise) in the `ViewModel` instead of a `LiveData` property.
260269
The `statIn` operator is used to convert the ordinary, cold `Flow` into a hot `StateFlow`.
261270

262271
In 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

Comments
 (0)