-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from develop-playground/feature/use-constructo…
…r-parameter ViewModel의 livedata로 값을 전달하지 않고 생성자 주입을 통해 id 전달
- Loading branch information
Showing
3 changed files
with
22 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 6 additions & 7 deletions
13
...in/java/github/dev_playground/jeju_road/presentation/ui/page/RestaurantDetailViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,21 @@ | ||
package github.dev_playground.jeju_road.presentation.ui.page | ||
|
||
import androidx.lifecycle.* | ||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.liveData | ||
import github.dev_playground.jeju_road.domain.model.DetailInformation | ||
import github.dev_playground.jeju_road.domain.usecase.GetRestaurantDetailUseCase | ||
import github.dev_playground.jeju_road.presentation.util.UiState | ||
import github.dev_playground.jeju_road.presentation.util.toUiState | ||
import kotlinx.coroutines.* | ||
|
||
class RestaurantDetailViewModel( | ||
id: Long, | ||
private val getRestaurantPageUseCase: GetRestaurantDetailUseCase | ||
) : ViewModel() { | ||
|
||
val id: MutableLiveData<Long> = MutableLiveData<Long>() | ||
|
||
val detailInformationState: LiveData<UiState<DetailInformation>> = id.switchMap { | ||
val detailInformationState: LiveData<UiState<DetailInformation>> = | ||
liveData { | ||
emit(UiState.loading()) | ||
emit(getRestaurantPageUseCase.invoke(it).toUiState()) | ||
emit(getRestaurantPageUseCase.invoke(id).toUiState()) | ||
} | ||
} | ||
} |