: ViewModel() { private val idolsLoadState: MutableStateFlow<LoadState> = MutableStateFlow(LoadState.Initialize) private val queryState: MutableStateFlow<String> = MutableStateFlow("") val uiModel: StateFlow<IdolsUiModel> get() = combine( idolsLoadState, queryState, ) { idolsLoadState, _ -> IdolsUiModel(idolsLoadState) }.distinctUntilChanged().stateIn(viewModelScope, SharingStarted.Eagerly, IdolsUiModel()) fun search(query: String? = null) { val job = viewModelScope.launch(start = CoroutineStart.LAZY) { runCatching { withContext(Dispatchers.Default) { repository.search(query) } } .onSuccess { idolsLoadState.value = LoadState.Loaded(it) } .onFailure { idolsLoadState.value = LoadState.Error(it) } } idolsLoadState.value = LoadState.Loading(job) job.start() } } ˒"OESPJEJ04ͷࠩΛҙࣝͤͣ ɹ6*ϩδοΫͷ࣮͕Մೳʹ🎉 ໊લݕࡧػೳΛ࣮ͨ͠ 7JFX.PEFM DPNNPO.BJO*EPMT7JFX.PEFMLU