Skip to content

Commit

Permalink
feat: extract detail arguments from saved state handle
Browse files Browse the repository at this point in the history
- Extract `id` and `image` from `savedStateHandle` using `toRoute()` instead of lazy initialization
- Removed unused `Detail` object creation and its corresponding code
- Replaced the `lazy { ... }` block with a single line of code to initialize the `args` variable directly
  • Loading branch information
shinhyo committed Sep 6, 2024
1 parent ee9391a commit af704cf
Showing 1 changed file with 2 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package io.github.shinhyo.brba.feature.detail
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.navigation.toRoute
import dagger.hilt.android.lifecycle.HiltViewModel
import io.github.shinhyo.brba.core.common.result.Result
import io.github.shinhyo.brba.core.common.result.asResult
Expand Down Expand Up @@ -47,12 +48,7 @@ class DetailViewModel @Inject constructor(
private val updateFavoriteUseCase: UpdateFavoriteUseCase,
) : ViewModel() {

private val args: Detail by lazy {
Detail(
id = checkNotNull(savedStateHandle.get<Long>("id")),
image = checkNotNull(savedStateHandle.get<String>("image")),
)
}
private val args = savedStateHandle.toRoute<Detail>()

private val _imageState = MutableStateFlow(args.id to args.image)
val imageState = _imageState.asStateFlow()
Expand Down

0 comments on commit af704cf

Please sign in to comment.