Skip to content

Commit

Permalink
web feedback: bumped versions, added imports (#263)
Browse files Browse the repository at this point in the history
  • Loading branch information
ElviraMustafina authored Oct 24, 2024
1 parent fe29f9e commit c4e10ec
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
34 changes: 18 additions & 16 deletions topics/compose/compose-viewmodel.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,27 @@ Using the [navigation example](https://github.com/JetBrains/compose-multiplatfor

1. Declare the ViewModel class:

```kotlin
class OrderViewModel : ViewModel() {
private val _uiState = MutableStateFlow(OrderUiState(pickupOptions = pickupOptions()))
val uiState: StateFlow<OrderUiState> = _uiState.asStateFlow()

// ...
}
```
```kotlin
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewmodel.compose.viewModel

class OrderViewModel : ViewModel() {
private val _uiState = MutableStateFlow(OrderUiState(pickupOptions = pickupOptions()))
val uiState: StateFlow<OrderUiState> = _uiState.asStateFlow()
// ...
}
```

2. Add the ViewModel to your composable function:

```kotlin
@Composable
fun CupcakeApp(
viewModel: OrderViewModel = viewModel { OrderViewModel() },
) {
// ...
}
```
```kotlin
@Composable
fun CupcakeApp(
viewModel: OrderViewModel = viewModel { OrderViewModel() },
) {
// ...
}
```

> When running coroutines in a `ViewModel`, remember that the `ViewModel.viewModelScope` value is tied to the `Dispatchers.Main.immediate` value,
> which might be unavailable on desktop by default.
Expand Down
4 changes: 2 additions & 2 deletions v.list
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

<var name="kmpncVersion" value="1.0.0-ALPHA-33" type="string"/>

<var name="composeNavigationVersion" value="2.7.0-alpha07" type="string"/>
<var name="composeNavigationVersion" value="2.8.0-alpha10" type="string"/>

<var name="composeViewmodelVersion" value="2.8.0" type="string"/>
<var name="composeViewmodelVersion" value="2.8.2" type="string"/>

</vars>

0 comments on commit c4e10ec

Please sign in to comment.