Skip to content

Commit af704cf

Browse files
committed
feat: extract detail arguments from saved state handle
- 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
1 parent ee9391a commit af704cf

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

feature/detail/src/main/kotlin/io/github/shinhyo/brba/feature/detail/DetailViewModel.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package io.github.shinhyo.brba.feature.detail
1818
import androidx.lifecycle.SavedStateHandle
1919
import androidx.lifecycle.ViewModel
2020
import androidx.lifecycle.viewModelScope
21+
import androidx.navigation.toRoute
2122
import dagger.hilt.android.lifecycle.HiltViewModel
2223
import io.github.shinhyo.brba.core.common.result.Result
2324
import io.github.shinhyo.brba.core.common.result.asResult
@@ -47,12 +48,7 @@ class DetailViewModel @Inject constructor(
4748
private val updateFavoriteUseCase: UpdateFavoriteUseCase,
4849
) : ViewModel() {
4950

50-
private val args: Detail by lazy {
51-
Detail(
52-
id = checkNotNull(savedStateHandle.get<Long>("id")),
53-
image = checkNotNull(savedStateHandle.get<String>("image")),
54-
)
55-
}
51+
private val args = savedStateHandle.toRoute<Detail>()
5652

5753
private val _imageState = MutableStateFlow(args.id to args.image)
5854
val imageState = _imageState.asStateFlow()

0 commit comments

Comments
 (0)